# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920149 | Faisal_Saqib | Cloud Computing (CEOI18_clo) | C++17 | 0 ms | 0 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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int N=2001;
long long c[N],f[N],v[N],C[N],F[N],V[N];
long long buy[N*50][2];
long long sell[N*50][2];
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>c[i]>>f[i]>>v[i];
}
for(int i=0;i<m;i++)
{
cin>>C[i]>>F[i]>>V[i];
}
// when all f=F
for(int i=0;i<=(50*n);i++)
buy[i][0]=1e18;
buy[0][0]=0;
for(int j=0;j<n;j++)
{
for(int i=0;i<=(50*n);i++)
if(buy[i][0]!=1e18)
buy[i+c[j]][1]=min(buy[i+c[j]][1],buy[i][0]+v[j]);
for(int i=0;i<=(50*n);i++)
buy[i][0]=min(buy[i][0],buy[i][1]);
}
for(int i=0;i<=(50*n);i++)
sell[i][0]=-1e18;
sell[0][0]=0;
for(int j=0;j<n;j++)
{
for(int i=0;i<=(50*n);i++)
if(sell[i][0]!=-1e18)
sell[i+c[j]][1]=max(sell[i+c[j]][1],sell[i][0]+v[j]);
for(int i=0;i<=(50*n);i++)
sell[i][0]=max(sell[i][0],sell[i][1]);
}
long long ans=0;
ll mx=-1e18;
for(int i=0;i<=(50*n);i++)
{
mx=max(mx,sell[i][0]);
ans=max(ans,mx-buy[i][0]);
}
cout<<ans<<'\n';
return 0;
}