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>
typedef long long ll;
using namespace std;
signed main()
{
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
ll n,m,M,ans,a,b,c,i,j;
cin>>n;
M=n*50+1;
vector <vector<ll> > g;
for(i=0;i<n;i++)
{
cin>>a>>b>>c;
g.push_back({b,1,a,c});
}
cin>>m;
for(i=0;i<m;i++)
{
cin>>a>>b>>c;
g.push_back({b,0,a,c});
}
sort(g.begin(),g.end());
vector<ll> dp(200020);
for(i=0;i<2*M+10;i++)
{
dp[i]=-1000000000000000000;
}
dp[0]=0;
for(i=n+m-1;i>=0;i--)
{
if(g[i][1]==0)
{
for(j=g[i][2];j<=M;j++)
{
dp[j-g[i][2]]=max(dp[j-g[i][2]],dp[j]+g[i][3]);
}
}
else
{
for(j=M;j>=0;j--)
{
dp[j+g[i][2]]=max(dp[j+g[i][2]],dp[j]-g[i][3]);
}
}
}
ans=0;
for(i=0;i<=M;i++)
{
ans=max(ans,dp[i]);
}
cout<<ans<<"\n";
}
# | 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... |