#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll const maxn = 1e5+1;
ll dp[maxn];
int main()
{
int n;
cin>>n;
vector<array<ll,4> > v;
for (int i=0;i<n;i++)
{
ll c,f,p;
cin>>c>>f>>p;
v.push_back({f,c,-p});
}
int m;cin>>m;
for (int i=0;i<m;i++)
{
ll c,f,p;
cin>>c>>f>>p;
v.push_back({f,-c,p});
}
/// f po golemina, prvin kupuvanje, c se dali kupuvam ili prodavam
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for (int i=0;i<maxn;i++) dp[i] = -1e15;
dp[0] = 0;
for (auto a: v)
{
ll cores = a[1],price = a[2];
if (cores < 0)
for (ll c = 0;c<maxn;c++)
{
if (c + cores < maxn && c+cores >= 0) {
//if (dp[c] > -2000) cout<<"dp["<<c<<"+"<<cores<<"] = "<<"max( "<<dp[c+cores]<<" , "<<dp[c]<<"+"<<price<<" )\n";
dp[c+cores] = max(dp[c+cores],dp[c] + price);
}
}
else
{
for (ll c = maxn-1;c>=0;c--)
{
if (c + cores < maxn && c+cores >= 0) {
//if (dp[c] > -2000) cout<<"dp["<<c<<"+"<<cores<<"] = "<<"max( "<<dp[c+cores]<<" , "<<dp[c]<<"+"<<price<<" )\n";
dp[c+cores] = max(dp[c+cores],dp[c] + price);
}
}
}
//cout<<"izlava za "<<price<<"\n";
}
ll odg = 0;
for (int i=0;i<maxn;i++) odg = max(odg,dp[i]);
cout<<odg<<endl;
return 0;
}
# | 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... |