Submission #1023681

#TimeUsernameProblemLanguageResultExecution timeMemory
1023681vjudge1Cloud Computing (CEOI18_clo)C++17
54 / 100
491 ms2180 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << endl #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n;cin>>n; ll c[n],f[n],v[n]; for(int i=0;i<n;i++) cin>>c[i]>>f[i]>>v[i]; int m;cin>>m; ll C[m],F[m],V[m]; for(int i=0;i<m;i++) cin>>C[i]>>F[i]>>V[i]; vector<pii> a; for(int i=0;i<n;i++) a.pb({f[i],i}); for(int i=0;i<m;i++) a.pb({F[i],n+i}); sort(all(a),greater<pii>()); ll dp[2][n*50+10]; for(int j=1;j<=n*50;j++) dp[1][j]=-1e15; dp[1][0]=0; for(int i=0;i<n+m;i++) { ll idx=a[i].se; for(int j=0;j<=n*50;j++) { dp[i%2][j]=dp[(i+1)%2][j]; if(idx<n && j-c[idx]>=0) dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j-c[idx]]-v[idx]); else if(idx>=n && j+C[idx-n]<=n*50) dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j+C[idx-n]]+V[idx-n]); } } ll ans=0; for(int j=0;j<=n*50;j++) ans=max(ans,dp[(n+m+1)%2][j]); cout<<ans; 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...