Submission #947158

#TimeUsernameProblemLanguageResultExecution timeMemory
947158asmalltyphoonCloud Computing (CEOI18_clo)C++17
100 / 100
415 ms2392 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; signed main() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); ll n,m,M,ans,a,b,c,i,j; cin>>n; M=n*50+1; vector <vector<ll> > g; for(i=0;i<n;i++) { cin>>a>>b>>c; g.push_back({b,1,a,c}); } cin>>m; for(i=0;i<m;i++) { cin>>a>>b>>c; g.push_back({b,0,a,c}); } sort(g.begin(),g.end()); vector<ll> dp(200020); for(i=0;i<2*M+10;i++) { dp[i]=-1000000000000000000; } dp[0]=0; for(i=n+m-1;i>=0;i--) { if(g[i][1]==0) { for(j=g[i][2];j<=M;j++) { dp[j-g[i][2]]=max(dp[j-g[i][2]],dp[j]+g[i][3]); } } else { for(j=M;j>=0;j--) { dp[j+g[i][2]]=max(dp[j+g[i][2]],dp[j]-g[i][3]); } } } ans=0; for(i=0;i<=M;i++) { ans=max(ans,dp[i]); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...