#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
struct trio{
int c, f, v;
};
bool custom(trio a, trio b){
if (a.f==b.f) return a.c>b.c;
return a.f>b.f;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k=0;
cin>>n;
vector<trio> vect(n);
for (int i=0; i<n; ++i)cin>>vect[i].c>>vect[i].f>>vect[i].v, vect[i].v*=-1, k+=vect[i].c;
cin>>m;
trio temp;
for (int i=0; i<m; ++i)cin>>temp.c>>temp.f>>temp.v, temp.c*=-1, vect.pb(temp);
sort(vect.begin(), vect.end(), custom);
vector<int> dp(k+1), prev(k+1, LLONG_MIN/2);
prev[0]=0;
for (int i=0; i<n+m; ++i){
dp=prev;
for (int j=max(0ll, vect[i].c); j<=min(k, k+vect[i].c); ++j)dp[j]=max(dp[j], prev[j-vect[i].c]+vect[i].v);
swap(dp, prev);
}
cout<<*max_element(prev.begin(), prev.end());
}
# | 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... |