# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033513 | warrenn | Cloud Computing (CEOI18_clo) | C++14 | 2551 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
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;
}
}
signed 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);
int dp[2][sum+1];
for(int q=0;q<=1;q++){
for(int w=0;w<=sum;w++){
dp[q][w]=-1e15;
}
}
dp[(n+m+1)%2][0]=0;
for(int q=n+m;q>=1;q--){
for(int w=0;w<=sum;w++){
auto [a,b,c,tipe]=barang[q-1];
dp[q%2][w]=dp[(q+1)%2][w];
if(tipe==0){
if(w-a>=0){
dp[q%2][w]=max(dp[q%2][w],dp[(q+1)%2][w-a]-c);
}
}
else{
if(w+a<=sum){
dp[q%2][w]=max(dp[q%2][w],dp[(q+1)%2][w+a]+c);
}
}
}
}
int ans=-1e15;
for(int q=0;q<=sum;q++){
ans=max(ans,dp[1][q]);
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |