This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Code by Parsa Eslami
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bit(i,j) ((j>>i)&1)
#define minm(x,y) x=min(x,y)
#define maxm(x,y) x=max(x,y)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cout<<#x<<": "<<x<<'\n'
#define wtf cout<<"WHAT THE FUCK!\n"
#define dmid int mid=(r+l)/2
#define lc 2*id
#define rc 2*id+1
using namespace std;
const int N=2e5+4;
ll dp[N];
vector<pair<int,pii>> vc;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
FOR(i,1,n){
int c,f,v; cin>>c>>f>>v;
vc.pb({f,{c,-v}});
}
int m; cin>>m;
FOR(i,1,m){
int c,f,v; cin>>c>>f>>v;
vc.pb({f,{-c,+v}});
}
FOR(i,1,N-1) dp[i]=-1e18;
sort(all(vc));
FORR(j,SZ(vc)-1,0){
int c=vc[j].S.F; int v=vc[j].S.S;
if(c<0){
FOR(i,0,N+c-1) maxm(dp[i],dp[i-c]+v);
}else{
FORR(i,N-1,c) maxm(dp[i],dp[i-c]+v);
}
}
ll ans=0;
FOR(i,0,N-1) maxm(ans,dp[i]);
cout<<ans<<'\n';
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... |