제출 #483313

#제출 시각아이디문제언어결과실행 시간메모리
483313MOUF_MAHMALATCloud Computing (CEOI18_clo)C++14
100 / 100
666 ms2628 KiB
#include<bits/stdc++.h> #define all(s) s.begin(),s.end() #define F first #define S second using namespace std; typedef int ll; struct node { ll c,f,v; bool tp=0; } a[40009]; bool cmp(const node&xo,const node&yo) { if(xo.f==yo.f) return xo.tp<yo.tp; return xo.f>yo.f; } ll n,m; long long dp[2][100001],ans=-1e15; int main() { ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; for(ll i=0; i<n; i++) cin>>a[i].c>>a[i].f>>a[i].v; cin>>m; for(ll i=n; i<n+m; i++) { cin>>a[i].c>>a[i].f>>a[i].v; a[i].tp=1; } sort(a,a+n+m,cmp); for(ll i=1; i<=1e5; i++) dp[1][i]=-1e15; for(ll i=0; i<n+m; i++) { bool b=i&1; for(ll j=0; j<=1e5; j++) { long long &r=dp[b][j]; r=dp[b^1][j]; if(a[i].tp&&j+a[i].c<=1e5) r=max(r,dp[b^1][j+a[i].c]+a[i].v); else if(a[i].tp==0&&j-a[i].c>=0) r=max(r,dp[b^1][j-a[i].c]-a[i].v); if(i==n+m-1) ans=max(ans,r); } } cout<<ans; 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...