Submission #953018

#TimeUsernameProblemLanguageResultExecution timeMemory
953018BF001Cloud Computing (CEOI18_clo)C++17
100 / 100
493 ms1436 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define M 100005 #define N 40005 #define oo 1e16 // struct ii{ int typ, c, f, v; bool operator < (ii o){ if (f == o.f) return typ < o.typ; return f > o.f; } } a[N]; int n, m, ma, dp[M]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].typ = 1; ma += a[i].c; } cin >> m; for (int i = n + 1; i <= n + m; i++){ cin >> a[i].c >> a[i].f >> a[i].v; a[i].typ = 2; } n += m; for (int i = 0; i <= ma; i++) dp[i] = -oo; dp[0] = 0; sort(a + 1, a + n + 1); int res = 0; for (int i = 1; i <= n; i++){ if (a[i].typ == 1){ for (int j = ma; j >= 0; j--){ if (j < a[i].c) break; if (dp[j - a[i].c] == -oo) continue; dp[j] = max(dp[j], dp[j - a[i].c] - a[i].v); res = max(res, dp[j]); } continue; } for (int j = 0; j <= ma; j++){ if (j + a[i].c > ma) break; if (dp[j + a[i].c] == -oo) continue; dp[j] = max(dp[j], dp[j + a[i].c] + a[i].v); res = max(res, dp[j]); } } cout << res; 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...