#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 5e18
#define nl '\n'
inline void solve(){
vector<tuple<int,int,int>> v;
int n;
cin>>n;
for(int i=0; i<n; i++){
int c, f, p;
cin>>c>>f>>p;
v.push_back({f, c, -p});
}
int m;
cin>>m;
for(int i=0; i<m; i++){
int c, f, p;
cin>>c>>f>>p;
v.push_back({f, -c, p});
}
sort(v.rbegin(), v.rend());
int cr = 50*n;
vector<int> ldp(cr+1, -inf), dp(cr+1);
ldp[0] = 0;
for(auto [f, c, p] : v){
for(int j=0; j<=cr; j++){
dp[j] = ldp[j];
if(0 <= j-c and j-c <= cr) dp[j] = max(dp[j], ldp[j-c] + p);
}
ldp = dp;
}
cout<<max(0ll, *max_element(ldp.begin(), ldp.end()));
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);cout.tie(NULL);
int t = 1;
//cin>>t;
while(t--) solve();
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... |