Submission #1023622

#TimeUsernameProblemLanguageResultExecution timeMemory
1023622vjudge1Cloud Computing (CEOI18_clo)C++17
54 / 100
304 ms2136 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() ll dp[2][100010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n;cin>>n; int c[n],f[n],v[n]; for(int i=0;i<n;i++) cin>>c[i]>>f[i]>>v[i]; int m;cin>>m; int 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>()); for(int j=1;j<=100000;j++) dp[1][j]=-1e18; for(int i=0;i<n+m;i++) { ll idx=a[i].se,val,q; if(idx>=n) idx-=n,val=V[idx],q=C[idx]; else val=-v[idx],q=-c[idx]; for(int j=0;j<=100000;j++) { dp[i%2][j]=dp[(i+1)%2][j]; if(0<=j+q && j+q<=100000) dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j+q]+val); } } ll ans=0; for(int j=0;j<=100000;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...