제출 #844850

#제출 시각아이디문제언어결과실행 시간메모리
844850GoldLightCloud Computing (CEOI18_clo)C++17
100 / 100
706 ms2140 KiB
#include <bits/stdc++.h> using namespace std; void fast(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);} #define int long long const int INF=-1e18; struct info{int x, y, z;}; bool cmp(info a, info b){ if(a.y!=b.y) return a.y>b.y; return a.z<b.z; } signed main(){ fast(); vector<info> v; int n, m=0; cin>>n; for(int i=1; i<=n; i++){ int x, y, z; cin>>x>>y>>z; v.push_back({x, y, -z}); m+=x; } cin>>n; for(int i=1; i<=n; i++){ int x, y, z; cin>>x>>y>>z; v.push_back({-x, y, z}); } sort(v.begin(), v.end(), cmp); vector<int> dp(m+1, INF); dp[0]=0; for(auto [x, y, z]:v){ vector<int> dp2=dp; for(int i=0; i<=m; i++){ int next=i+x; if(next>=0 && next<=m && dp[i]!=INF){ dp2[next]=max(dp2[next], dp[i]+z); } } dp=dp2; } cout<<*max_element(dp.begin(), dp.end()); } /* int main(){ fast(); int n; cin>>n; vector<tuple<int,int>> a; int s[n], t[n], w[n]; for(int i=0; i<n; i++){ cin>>s[i]>>t[i]; a.push_back({t[i], s[i], i}); } sort(a.begin(), a.end()); } */ /* int main(){ fast(); int n, m; cin>>n; int a[n+1], b[n+1], c[n+1]; bool s3=true; for(int i=1; i<=n; i++){ cin>>a[i]>>b[i]>>c[i]; } cin>>m; int x[m+1], y[m+1], z[m+1]; for(int i=1; i<=m; i++){ cin>>x[i]>>y[i]>>z[i]; } }*/
#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...