結果
問題 | No.974 最後の日までに |
ユーザー |
![]() |
提出日時 | 2020-01-21 22:03:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,927 bytes |
コンパイル時間 | 1,446 ms |
コンパイル使用メモリ | 169,436 KB |
実行使用メモリ | 36,664 KB |
最終ジャッジ日時 | 2024-07-06 08:07:35 |
合計ジャッジ時間 | 7,800 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 48 |
ソースコード
#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>; signed main() { int w; cin >> w; vi a(w), b(w), c(w); rep(i, 0, w) cin >> a[i] >> b[i] >> c[i]; auto solve = [&](int n1, int n2){ map<int, int> first; rep(mask, 0, 1<<n1){ int money = 0, like = 0; bool ok = true; rep(i, 0, n1) if(mask & 1<<i){ if(i+1 < n1 and (mask & 1<<(i+1))){ like += b[i+1]; money -= c[i+1]; i++; } else { ok = false; break; } } else { money += a[i]; } if(ok) first[money] = like; } int ma = -1e15; for(auto i = first.rbegin(); i != first.rend(); i++){ chmax(ma, i->second); chmax(i->second, ma); // cout << i->first << " " << i->second << endl; } int ans = 0; rep(mask, 0, 1<<n2){ int money = 0, like = 0; bool ok = true; rep(i, 0, n2) if(mask & 1<<i){ if(i+1 < n2 and (mask & 1<<(i+1))){ like += b[n1+i+1]; money -= c[n1+i+1]; i++; } else { ok = false; break; } } else { money += a[n1+i]; } if(ok){ // cout << money << " " << like << endl; auto j = first.lower_bound(-money); if(j != first.end()){ chmax(ans, like + j->second); } } } return ans; }; int n1 = w/2; int n2 = w-n1; cout << max(solve(n1, n2), solve(n1+1, n2-1)) << endl; // cout << solve(n1, n2) << endl; // cout << solve(n1+1, n2-1) << endl; return 0; }