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;
int n,m,c,f,value,c2,f2,value2,core,cost,type,fraud,holo;
long long dp[2][100005];
tuple<int,int,int,int> v[4005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&c,&f,&value);
v[i-1]={f,2,c,value};
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&c2,&f2,&value2);
v[n+i-1]={f2,1,c2,value2};
}
v[n+m]={-1,-1,-1,-1};
sort(v,v+n+m+1);
for(int i=0;i<=1;i++)
{
for(int j=0;j<=100000;j++)
{
dp[i][j]=-1e18;
}
}
dp[0][0]=0;
for(int i=1;i<=n+m;i++)
{
fraud=get<0>(v[i]);
core=get<2>(v[i]);
cost=get<3>(v[i]);
type=get<1>(v[i]);
//printf("%d %d %d %d\n",fraud,core,cost,type);
holo=i%2;
for(int j=0;j<=100000;j++)
{
dp[holo][j]=dp[1-(holo)][j];
}
for(int j=0;j<=100000;j++)
{
if(type==1)
{
if(j+core<=100000)
{
dp[holo][j+core]=max(dp[holo][j+core],dp[1-(holo)][j]+cost);
}
}else
{
dp[holo][max(j-core,0)]=max(dp[holo][max(j-core,0)],dp[1-(holo)][j]-cost);
}
}
}
printf("%lld\n",dp[(n+m)%2][0]);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
clo.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d%d",&c,&f,&value);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
clo.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d%d%d",&c2,&f2,&value2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |