제출 #1023647

#제출 시각아이디문제언어결과실행 시간메모리
1023647vjudge1Cloud Computing (CEOI18_clo)C++17
54 / 100
559 ms2140 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; for(int j=0;j<=100000;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]<=100000) 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<=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...