// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=1e9+7;
const int inf = 1e14;
const int LOG=17;
const int N=2e5+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
int dp[N];
void solve(){
cin >> n;
vector<pair<pair<int,int>,pair<int,int>>>a(n);
for (int i=0;i<n;i++){
cin >> a[i].se.fi >> a[i].fi.fi >> a[i].se.se;
a[i].fi.se=2;
}
cin >> m;
for (int i=0;i<m;i++){
pair<pair<int,int>,pair<int,int>>b;
cin >> b.se.fi >> b.fi.fi >> b.se.se;
b.fi.se=1;
a.push_back(b);
}
sort(a.rbegin(),a.rend());
for (int i=0;i<N;i++){
dp[i]=-inf;
}
dp[0]=0;
int s=0;
for (int j=0;j<n+m;j++){
int t=a[j].fi.se;
int c=a[j].se.fi;
int v=a[j].se.se;
s+=c;
if (t==2){
for (int i=s+c;i>=c;i--){
dp[i]=max(dp[i],dp[i-c]-v);
}
}
else{
for (int i=0;i<=s;i++){
dp[i]=max(dp[i],dp[i+c]+v);
}
}
}
int ans=0;
for (int i=0;i<N;i++){
ans=max(ans,dp[i]);
}
cout << ans << endl;
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r" ,stdin);
// freopen("output.txt","w",stdout);
// #endif
ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
cout << fixed << setprecision(9);
srand(time(0));
// int t=1;
// cin >> t;
for (int _=1;_<=t;_++){
solve();
q++;
}
}
| # | 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... |