제출 #617558

#제출 시각아이디문제언어결과실행 시간메모리
617558codr0Cloud Computing (CEOI18_clo)C++14
100 / 100
636 ms2052 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...