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;
long long n,m,c,f,value,c2,f2,value2,dp[2][10005],core,cost,type,fraud;
vector<tuple<long long,long long,long long,long long> > v;
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld%lld",&c,&f,&value);
v.push_back({f,c,value,2});
}
scanf("%lld",&m);
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&c2,&f2,&value2);
v.push_back({f2,c2,value2,1});
}
v.push_back({-1,-1,-1,-1});
sort(v.begin(),v.end());
for(int i=0;i<=1;i++)
{
for(int j=0;j<=10000;j++)
{
dp[i][j]=-1e18;
}
}
dp[0][0]=0;
for(int i=1;i<=n+m;i++)
{
fraud=get<0>(v[i]);
core=get<1>(v[i]);
cost=get<2>(v[i]);
type=get<3>(v[i]);
//printf("%lld %lld %lld %lld\n",fraud,core,cost,type);
}
for(int i=1;i<v.size();i++)
{
fraud=get<0>(v[i]);
core=get<1>(v[i]);
cost=get<2>(v[i]);
type=get<3>(v[i]);
//printf("%d %d %d %d\n",fraud,core,cost,type);
for(int j=0;j<=10000;j++)
{
dp[i%2][j]=-1e18;
}
for(int j=0;j<=10000;j++)
{
if(type==1)
{
if(j+core<=10000)
{
dp[i%2][j+core]=max(dp[i%2][j+core],dp[1-(i%2)][j]+cost);
}
}else
{
dp[i%2][max(j-core,(long long)0)]=max(dp[i%2][max(j-core,(long long)0)],dp[1-(i%2)][j]-cost);
}
}
for(int j=0;j<=10000;j++)
{
dp[i%2][j]=max(dp[i%2][j],dp[1-(i%2)][j]);
}
/*printf("%d\n",i);
for(int j=0;j<=20;j++)
{
printf("%lld ",dp[i%2][j]);
}
printf("\n");*/
}
printf("%lld\n",dp[(n+m)%2][0]);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=1;i<v.size();i++)
| ~^~~~~~~~~
clo.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
clo.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%lld%lld%lld",&c,&f,&value);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%lld",&m);
| ~~~~~^~~~~~~~~~~
clo.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%lld%lld%lld",&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... |