제출 #1033516

#제출 시각아이디문제언어결과실행 시간메모리
1033516vjudge1Cloud Computing (CEOI18_clo)C++17
0 / 100
1935 ms262144 KiB
#include<bits/stdc++.h> using namespace std; bool cmp(tuple<int,int,int,int>q,tuple<int,int,int,int>w ){ auto &[a,b,c,type]=q; auto &[d,e,f,tipe]=w; if(b!=e){ return b<e; } else{ return type>tipe; } } int main(){ int n; cin>>n; vector<tuple<int,int,int,int> > barang; int sum=0; for(int q=1;q<=n;q++){ int a,b,c; cin>>a>>b>>c; barang.push_back({a,b,c,0}); sum+=b; } int m; cin>>m; for(int q=1;q<=m;q++){ int a,b,c; cin>>a>>b>>c; barang.push_back({a,b,c,1}); } sort(barang.begin(),barang.end(),cmp); long long dp[sum+2]; for(int w=0;w<=sum;w++){ dp[w]=-1e15; } dp[0]=0; for(int q=n+m;q>=1;q--){ auto [a,b,c,tipe]=barang[q-1]; if(tipe==0){ for(int w=sum;w>=a;w--){ dp[w]=max(dp[w],dp[w-a]-c); } } else{ for(int w=0;w+a<=sum;w++){ dp[w]=max(dp[w],dp[w+a]+c); } } } long long ans=0; for(int q=0;q<=sum;q++){ ans=max(ans,dp[q]); } cout<<ans<<endl; }
#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...