#include "bits/stdc++.h"
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
int dp[4002][4004];
int n,m;
vector<pair<int,pair<int,int> > >vp;
int fun(int idx,int crs) {
if(crs<0)
return -1e15;
if(idx==n+m) {
return 0;
}
int &ret=dp[idx][crs];
if(~ret)
return ret;
return ret=max(vp[idx].s.s+fun(idx+1,crs+vp[idx].s.f),fun(idx+1,crs));
}
signed main() {
memset(dp,-1,sizeof dp);
cin>>n;
for(int i=0;i<n;i++) {
int c,f,v;
cin>>c>>f>>v;
vp.pb({f,{c,-v}});
}
cin>>m;
for(int i=0;i<m;i++) {
int c,f,v;
cin>>c>>f>>v;
vp.pb({f,{-c,v}});
}
sort(vp.rbegin(),vp.rend());
int ans=fun(0,0);
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... |