제출 #1034405

#제출 시각아이디문제언어결과실행 시간메모리
1034405vjudge1Cloud Computing (CEOI18_clo)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; struct thing{ int core,clock,price,type; }; bool cmp(thing q,thing w ){ if(q.clock!=w.clock){ return q.clock<w.clock; } else{ return q.type>w.type; } } int main(){ int n; cin>>n; thing barang[n+1]; vector<thing>tmp; int sum=0; for(int q=1;q<=n;q++){ cin>>barang[q-1].core>>barang[q-1].clock>>barang[q-1].price; barang[q-1].type=0; tmp.push_back(barang[q-1]); sum+=barang[q-1].price; } int m; cin>>m; for(int q=1;q<=m;q++){ cin>>barang[n+q-1].core>>barang[n+q-1].clock>>barang[n+q-1].price; barang[n+q-1].type=1; tmp.push_back(barang[n+q-1]); } sort(tmp.begin(),tmp.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]=tmp[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...