제출 #682097

#제출 시각아이디문제언어결과실행 시간메모리
682097sz1218Cloud Computing (CEOI18_clo)C++14
100 / 100
840 ms2012 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef pair<pi, ll> pl; #define f first #define s second const int NN = 1e5+3; int n, m; ll dp[2][NN]; struct S{ int c; int f; ll v; bool operator<(const S& y){ if(f == y.f)return c > y.c; return f > y.f; } }; S trans[4003]; int main() { //setIO(""); cin >> n; ll v; for(int i=1, c, f;i<=n;i++){ cin >> c >> f >> v; trans[i] = S{c, f, -v}; } cin >> m; for(int i=1, c, f;i<=m;i++){ cin >> c >> f >> v; trans[n+i] = S{-c, f, v}; } sort(trans+1, trans + n + m + 1); for(int i=1;i<=50*m;i++){ dp[0][i] = dp[1][i] = -1e18; } for(int t=1;t<=n+m;t++){ int p = t % 2; for(int i=0;i<=50*m;i++){ dp[p][i] = dp[1-p][i]; int ni = i - trans[t].c; if(ni >= 0 && ni <= 50*m && dp[1-p][ni] != -1e18){ dp[p][i] = max(dp[p][i], dp[1-p][ni] + trans[t].v); } } } ll ans = 0; for(int i=0;i<=50*m;i++){ ans = max(ans, dp[(n+m)%2][i]); } cout << ans << endl; 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...