이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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... |