結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
utouto97
|
| 提出日時 | 2020-01-21 22:12:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,201 bytes |
| コンパイル時間 | 1,712 ms |
| コンパイル使用メモリ | 167,316 KB |
| 実行使用メモリ | 15,376 KB |
| 最終ジャッジ日時 | 2024-07-06 08:40:56 |
| 合計ジャッジ時間 | 4,928 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 WA * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}
/*
*/
using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;
int w, a[55], b[55], c[55];
void dfs(int i, int n, int money, int like, vector<P> &v){
if(i == n){
v.emplace_back(money, like);
return;
}
dfs(i+1, n, money+a[i], like, v);
if(i+1 < n) dfs(i+2, n, money-c[i+1], like+b[i+1], v);
}
int solve(int half){
vector<P> x, y;
dfs(0, half, 0, 0, x);
dfs(half, w, 0, 0, y);
sort(all(x)); sort(all(y));
int ma = -1e15;
for(auto i = x.rbegin(); i != x.rend(); i++){
chmax(ma, i->second);
chmax(i->second, ma);
}
int ans = 0;
for(auto i : y){
auto j = lower_bound(all(x), P(-i.first, 0LL));
if(j == x.end()) continue;
chmax(ans, j->second + i.second);
}
return ans;
}
signed main() {
cin >> w;
rep(i, 0, w) cin >> a[i] >> b[i] >> c[i];
cout << solve(w/2) << endl;
return 0;
}
utouto97