Submission #1091756

#TimeUsernameProblemLanguageResultExecution timeMemory
1091756gygCloud Computing (CEOI18_clo)C++17
36 / 100
568 ms3920 KiB
#pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define int long long #define arr array const int MX_N = 2e3 + 5, MX_M = 2e3 + 5, MX_C = 1e5 + 5, INF = 1e15; int n, m; struct Evnt { bool is_gn; int cp, pwr, vl; bool operator<(Evnt othr) { if (othr.pwr == pwr) return is_gn; return pwr > othr.pwr; } }; arr<Evnt, MX_N + MX_M> evnt; arr<arr<int, MX_C>, 2> dp; void cmp() { for (int c = 1; c <= 1e5; c++) dp[0][c] = -INF; dp[0][0] = 0; for (int i = 1; i <= n + m; i++) { int prty = i % 2, opp_prty = (i + 1) % 2; if (evnt[i].is_gn) { for (int c = 0; c <= 1e5; c++) { if (c - evnt[i].cp >= 0) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c - evnt[i].cp] - evnt[i].vl); else dp[prty][c] = dp[opp_prty][c]; } } else { for (int c = 0; c <= 1e5; c++) { if (c + evnt[i].cp <= 1e5) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c + evnt[i].cp] + evnt[i].vl); else dp[prty][c] = dp[opp_prty][c]; } } } } signed main() { // freopen("cld.in", "r", stdin); cin >> n; for (int i = 1; i <= n; i++) { int cp, pwr, vl; cin >> cp >> pwr >> vl; evnt[i] = {true, cp, pwr, vl}; } cin >> m; for (int i = 1; i <= m; i++) { int cp, pwr, vl; cin >> cp >> pwr >> vl; evnt[n + i] = {false, cp, pwr, vl}; } sort(evnt.begin() + 1, evnt.begin() + n + m + 1); cmp(); int ans = -INF; for (int c = 0; c <= 1e5; c++) ans = max(ans, dp[(n + m) % 2][c]); cout << ans << '\n'; }
#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...