#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define eb push_back
#define ll long long
#define fi first
#define se second
int i,n,j,u,v,tmp,m;
const int maxn = 1e5+10;
const ll inf = 1e17;
struct bruh
{
int c,f,t;
bool operator < (bruh & pmt)
{
if(f == pmt.f)return c > pmt.c;
return f > pmt.f;
}
};
vector<bruh> a;
ll dp[2][maxn],mx;
bool now = 0,pre;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(i = 1;i<maxn;i++)dp[0][i] = -inf;
dp[0][0] = 0;
cin>>n;
for(i = 1;i<=n;i++)
{
cin>>u>>v>>tmp;
a.eb({u,v,-tmp});
}
cin>>m;
for(i = 1;i<=m;i++)
{
cin>>u>>v>>tmp;
a.eb({-u,v,tmp});
}
sort(all(a));
for(const bruh &tmp : a)
{
now = !now;
pre = !now;
// cout<<tmp.c<<' '<<tmp.f<<' '<<tmp.t<<'\n';
for(i = 0;i<maxn;i++)dp[now][i] = dp[pre][i];
for(i = max(0,tmp.c);i<min(maxn,maxn + tmp.c);i++)
{
if(dp[pre][i - tmp.c] != -inf)dp[now][i] = max(dp[now][i],dp[pre][i - tmp.c] + tmp.t);
mx = max(mx,dp[now][i]);
}
}
cout<<mx;
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... |