Submission #841820

#TimeUsernameProblemLanguageResultExecution timeMemory
841820WLZCloud Computing (CEOI18_clo)C++17
100 / 100
516 ms2908 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll LINF = (ll) 1e18; const int maxc = 10003; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector< tuple<int, int, int> > a; int sum_c = 0; for (int i = 0; i < n; i++) { int c, f, v; cin >> c >> f >> v; sum_c += c; a.emplace_back(f, v, c); } int m; cin >> m; for (int i = 0; i < m; i++) { int c, f, v; cin >> c >> f >> v; a.emplace_back(f, -v, c); } sort(a.rbegin(), a.rend()); vector< vector<ll> > dp(2, vector<ll>(sum_c + 1, -LINF)); dp[0][0] = 0; for (int i = 0; i < n + m; i++) { int cur = i % 2; int f, v, c; tie(f, v, c) = a[i]; for (int j = 0; j <= sum_c; j++) dp[!cur][j] = dp[cur][j]; if (v > 0) for (int j = 0; j + c <= sum_c; j++) dp[!cur][j + c] = max(dp[!cur][j + c], dp[cur][j] - v); else for (int j = c; j <= sum_c; j++) dp[!cur][j - c] = max(dp[!cur][j - c], dp[cur][j] - v); } cout << *max_element(dp[(n + m) % 2].begin(), dp[(n + m) % 2].end()) << '\n'; 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...