結果
問題 |
No.974 最後の日までに
|
ユーザー |
![]() |
提出日時 | 2019-12-11 14:17:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,324 bytes |
コンパイル時間 | 2,174 ms |
コンパイル使用メモリ | 205,620 KB |
最終ジャッジ日時 | 2025-01-08 10:51:41 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 10000000000000000 vector<pair<long long,long long>> V1,V2,V3,V4; void dfs1(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool flag){ int n = a.size(); if(ind==n){ if(flag) V2.emplace_back(money,love); else V1.emplace_back(money,love); return; } if(flag){ dfs1(a,b,c,ind+1,love+b[ind],money-c[ind],false); } else{ dfs1(a,b,c,ind+1,love,money+a[ind],false); dfs1(a,b,c,ind+1,love,money,true); } } void dfs2(vector<long long> &a,vector<long long> &b,vector<long long> &c,int ind,long long love,long long money,bool f,bool flag){ int n = a.size(); if(ind==n){ if(flag)return; if(f)V3.emplace_back(money,love); else V4.emplace_back(money,love); return; } if(flag){ dfs2(a,b,c,ind+1,love+b[ind],money-c[ind],f,false); } else{ dfs2(a,b,c,ind+1,love,money+a[ind],f,false); dfs2(a,b,c,ind+1,love,money,f,true); } } int main(){ int D; cin>>D; vector<long long> a(D),b(D),c(D); for(int i=0;i<D;i++){ cin>>a[i]>>b[i]>>c[i]; } vector<long long> a1,a2,b1,b2,c1,c2; for(int i=0;i<D;i++){ if(i<D/2){ a1.push_back(a[i]); b1.push_back(b[i]); c1.push_back(c[i]); } else{ a2.push_back(a[i]); b2.push_back(b[i]); c2.push_back(c[i]); } } dfs1(a1,b1,c1,0,0,0,false); dfs2(a2,b2,c2,0,0,0,true,false); if(b2.size()!=0)dfs2(a2,b2,c2,0,0,0,true,true); sort(V3.begin(),V3.end()); sort(V4.begin(),V4.end()); long long last = 0; for(auto it = V3.rbegin();it!=V3.rend();it++){ (*it).second = max((*it).second,last); last = (*it).second; } last=0; for(auto it = V4.rbegin();it!=V4.rend();it++){ (*it).second = max((*it).second,last); last = (*it).second; } long long ans = 0; pair<long long,long long> P = make_pair(0,-Inf); for(int i=0;i<V1.size();i++){ P.first = -V1[i].first; auto it = lower_bound(V3.begin(),V3.end(),P); if(it==V3.end())continue; ans = max(ans,V1[i].second + (*it).second); } for(int i=0;i<V2.size();i++){ P.first = -V2[i].first; auto it = lower_bound(V4.begin(),V4.end(),P); if(it==V4.end())continue; ans = max(ans,V2[i].second + (*it).second); } cout<<ans<<endl; return 0; }