Submission #752844

#TimeUsernameProblemLanguageResultExecution timeMemory
752844nguyenneheheCloud Computing (CEOI18_clo)C++17
72 / 100
601 ms1836 KiB
#include<bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector<array<int, 4>> a; int sumc = 0; for (int i = 0; i < n; ++i) { int c, f, v; cin >> c >> f >> v; a.push_back({c, f, -v, 0}); sumc += c; } int m; cin >> m; for (int i = 0; i < m; ++i) { int c, f, v; cin >> c >> f >> v; a.push_back({-c, f, v, 1}); } sort(a.begin(), a.end(), [](array<int, 4> x, array<int, 4> y) { return x[1] > y[1]; if (x[1] != y[1]) return x[1] > y[1]; return x[0] < y[0]; }); const long long INF = 2e18; vector<long long> dp(sumc + 1, -INF); dp[0] = 0; for (auto [c, f, v, ignored]: a) { vector<long long> cur = dp; for (int w = 0; w <= sumc; ++w) { int req = w - c; if (req < 0 || req > sumc) continue; if (dp[req] == -INF) continue; cur[w] = max(cur[w], dp[req] + v); } swap(dp, cur); } cout << *max_element(dp.begin(), dp.end()); }
#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...