Submission #471112

#TimeUsernameProblemLanguageResultExecution timeMemory
471112CrocoCloud Computing (CEOI18_clo)C++17
100 / 100
504 ms1368 KiB
#include <bits/stdc++.h> #define int long long int #define ll long long using namespace std; const int N = 1e5 + 5; int dp[N]; signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; vector<tuple<int,int,int>> v; for(int i=0;i<n;i++) { int c,f,cost; cin>>c>>f>>cost; v.push_back(make_tuple(f,cost,c)); } int m; cin>>m; for(int i=0;i<m;i++) { int c,f,cost; cin>>c>>f>>cost; v.push_back(make_tuple(f,-cost,c)); } sort(v.begin(),v.end()); const int inf = 1e15 + 5; for(int i=0;i<N;i++) dp[i] = -inf; dp[0] = 0; int ans = 0; for(int i=v.size()-1;i>=0;i--) { int c,f,cost; tie(f,cost,c) = v[i]; cost = -cost; if(cost < 0) //buying { for(int j=N-1;j>=0;j--) { if(j + c < N) dp[j + c] = max(dp[j + c],dp[j] + cost); } } else { for(int j=0;j<N;j++) { if(j - c >= 0) dp[j - c] = max(dp[j - c],dp[j] + cost); } } } for(int i=0;i<N;i++) ans = max(ans,dp[i]); cout << ans; }
#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...