Submission #496584

#TimeUsernameProblemLanguageResultExecution timeMemory
496584DDTerziev04Cloud Computing (CEOI18_clo)C++14
0 / 100
1 ms332 KiB
#include<iostream> #include<tuple> #include<vector> #include<algorithm> using namespace std; const int MAXN=2000, MAXC=500; const long long INF=1e18; bool CompareTuples(tuple<int, int, int> a, tuple<int, int, int> b) { return get<1>(a)>get<1>(b); } tuple<int, int, int> p[2*MAXN]; long long dp[2*MAXN+1][MAXC+1]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i=0; i<n; i++) { int c, f, v; cin >> c >> f >> v; p[i]={c, f, -v}; } int m; cin >> m; for(int i=n; i<n+m; i++) { int c, f, v; cin >> c >> f >> v; p[i]={-c, f, v}; } sort(p, p+n+m, CompareTuples); for(int i=0; i<n+m; i++) { cout << get<0>(p[i]) << " " << get<1>(p[i]) << " " << get<2>(p[i]) << "\n"; } for(int i=0; i<=n+m; i++) { for(int j=0; j<=MAXC; j++) { dp[i][j]=-INF; } } dp[0][0]=0; long long ans=0; for(int i=0; i<n+m; i++) { for(int j=0; j<=MAXC; j++) { int c, f, v; tie(c, f, v)=p[i]; dp[i+1][j]=max(dp[i+1][j], dp[i][j]); if(j+c>=0 && j+c<=MAXC) { dp[i+1][j+c]=max(dp[i+1][j+c], dp[i][j]+v); } ans=max(ans, dp[i][j]); } } for(int i=0; i<=MAXC; i++) { ans=max(ans, dp[n+m][i]); } cout << ans << "\n"; return 0; }
#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...