#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define ll long long
const int N = 4005;
const int C = N*25;
const ll inf = 1e16;
int n,q,tot;
struct DATA{
int c,f,v,t;
bool operator < (const DATA &o) const{
if(f==o.f) return t>o.t;
return f>o.f;
}
void print() {cerr<<c<<" "<<f<<" "<<v<<" "<<t<<"\n";}
}a[N];
ll dp[2][C];
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
if(fopen("TASK.INP", "r")){
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
cin>>n;
for(int i=1;i<=n;i++) {
int c,f,v; cin>>c>>f>>v;
a[++tot] = {c,f,v,0};
}
cin>>q;
for(int i=1;i<=q;i++){
int c,f,v; cin>>c>>f>>v;
a[++tot] = {c,f,v,1};
}
sort(a+1,a+tot+1);
// for(int i=1;i<=tot;i++) a[i].print();
fill_n(&dp[0][0], sizeof(dp)/sizeof(dp[0][0]), -inf);
dp[0][0] = 0;
for(int i=1;i<=tot;i++){
int c= a[i].c, f= a[i].f, v= a[i].v, t= a[i].t;
for(int j=0;j<10;j++){
ll &res = dp[i&1][j];
res = dp[(i-1)&1][j];
if(t){
if(j+c<C) res = max(res, dp[(i-1)&1][j+c]+v);
}
else{
if(j-c>=0) res = max(res, dp[(i-1)&1][j-c]-v);
}
// cerr<<i<<' '<<j<<' '<<res<<"\n";
}
}
cout<<*max_element(&dp[tot&1][0], &dp[tot&1][C-1]+1);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:30:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("TASK.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen("TASK.OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |