Submission #601739

#TimeUsernameProblemLanguageResultExecution timeMemory
601739pakhomoveeCloud Computing (CEOI18_clo)C++17
100 / 100
538 ms1440 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> using namespace std; #define int long long const int inf = 1e18; const int maxn = 100'001; int dp[maxn]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<pair<int, int>, pair<int, int>>> vv; for (int i = 0; i < n; ++i) { int c, f, v; cin >> c >> f >> v; vv.push_back({ { f, -1 }, { v, c } }); } int m; cin >> m; for (int i = 0; i < m; ++i) { int c, f, v; cin >> c >> f >> v; vv.push_back({ { f, -2 }, { v, c } }); } sort(vv.rbegin(), vv.rend()); fill(dp, dp + maxn, -inf); dp[0] = 0; for (pair<pair<int, int>, pair<int, int>> x : vv) { auto [p, q] = x; auto [f, t] = p; auto [v, c] = q; if (t == -1) { for (int j = maxn - 1; j >= c; --j) { dp[j] = max(dp[j - c] - v, dp[j]); } } else { for (int j = 0; j + c < maxn; ++j) { dp[j] = max(dp[j], dp[j + c] + v); } } } cout << *max_element(dp, dp + maxn); }
#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...