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;
const long long maxn = 5005;
struct query
{
long long idx;
long long c,f,v;
};
query q[maxn];
long long cores[200005][2];
bool cmp(query i, query j)
{
if(i.f==j.f)
{
return i.v<j.v;
}
return i.f>j.f;
}
long long SUM = 0;
long long n,m;
void solve()
{
long long i,j;
long long maxs= n*50;
for(i=1;i<=maxs;i++)
cores[i][0] = -1e18;
cores[0][0] = 0;
bool fl = 1;
for(i=1;i<=n+m;i++)
{
// cout<<q[i].c<<" "<<q[i].f<<" "<<q[i].v<<endl;
for(j=0;j<=maxs;j++)
{
cores[j][fl] = -1e18;
if(j==0)cores[j][fl]=0;
if((j-q[i].c)>=0&&(j-q[i].c)<=maxs)
{
cores[j][fl] = max(cores[j][fl],max(cores[j][!fl],cores[j-q[i].c][!fl]+q[i].v));
}
//cout<<j<<" -> "<<cores[j][fl]<<endl;
}
fl=!fl;
}
long long ans = -1e18;
for(i=0;i<=maxs;i++)
{
ans = max(ans,cores[i][!fl]);
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long i,j;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>q[i].c>>q[i].f>>q[i].v;
q[i].v = -q[i].v;
}
cin>>m;
for(i=1;i<=m;i++)
{
cin>>q[n+i].c>>q[n+i].f>>q[n+i].v;
q[n+i].c = -q[n+i].c;
}
sort(q+1,q+m+n+1,cmp);
//cout<<"OK"<<endl;
solve();
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:58:17: warning: unused variable 'j' [-Wunused-variable]
58 | long long i,j;
| ^
# | 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... |