This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct node{
int c,f,v,t;
bool operator<(const node& y)const{
if(f!=y.f) return f>y.f;
return t>y.t;
}
};
const int mxm=2000*50+5;
const ll inf=1e18;
int main() {_
int n;
cin>>n;
vector<node> vec;
for(int i=0;i<n;i++){
int c,f,v,t;
cin>>c>>f>>v;
t=1;
vec.push_back({c,f,v,t});
}
int m;
cin>>m;
for(int i=0;i<m;i++){
int c,f,v,t;
cin>>c>>f>>v;
t=-1;
vec.push_back({c,f,v,t});
}
sort(all(vec));
vector<ll> dp(mxm,-inf);
dp[0]=0;
for(auto v:vec){
//cout<<v.c<<' '<<v.f<<' '<<v.v<<' '<<v.t<<'\n';
if(v.t==1){
for(int i=mxm-1;i>=v.c;i--){
dp[i]=max(dp[i],dp[i-v.c]-v.v);
}
}
else{
for(int i=0;i<mxm-v.c;i++){
dp[i]=max(dp[i],dp[i+v.c]+v.v);
}
}
//cout<<*max_element(all(dp))<<'\n';
}
cout<<*max_element(all(dp))<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
//rrrahhh<3
//sharkkk<3
//by 林晉宇
Compilation message (stderr)
clo.cpp: In function 'void setIO(std::string)':
clo.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "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... |