제출 #575630

#제출 시각아이디문제언어결과실행 시간메모리
575630andrei_boacaCloud Computing (CEOI18_clo)C++14
100 / 100
775 ms2124 KiB
#include <bits/stdc++.h> #define CMAX 100000 using namespace std; typedef long long ll; ll n,m; struct date { int tip; ll c,f,p; } v[5005]; ll dp[2][CMAX+5]; bool comp(date a, date b) { if(a.f!=b.f) return a.f>b.f; return a.tip<b.tip; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { v[i].tip=1; cin>>v[i].c>>v[i].f>>v[i].p; } cin>>m; for(int i=1;i<=m;i++) { v[i+n].tip=2; cin>>v[i+n].c>>v[i+n].f>>v[i+n].p; } sort(v+1,v+n+m+1,comp); for(int i=1;i<=CMAX;i++) dp[0][i]=-1e17; ll ans=0; for(int i=1;i<=n+m;i++) { for(int c=0;c<=CMAX;c++) { dp[1][c]=dp[0][c]; if(v[i].tip==1) { if(c>=v[i].c) dp[1][c]=max(dp[1][c],dp[0][c-v[i].c]-v[i].p); } else { if(c+v[i].c<=CMAX) dp[1][c]=max(dp[1][c],dp[0][c+v[i].c]+v[i].p); } ans=max(ans,dp[1][c]); } for(int c=0;c<=CMAX;c++) dp[0][c]=dp[1][c]; } 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...