Submission #957451

#TimeUsernameProblemLanguageResultExecution timeMemory
957451DragosC1Cloud Computing (CEOI18_clo)C++17
100 / 100
1453 ms3924 KiB
#include <bits/stdc++.h> using namespace std; struct pc { int core; int freq; int value; } pc1[2001], pc2[2001], a[4001]; bool csort(pc a, pc b) { if (a.freq > b.freq) return 1; else if (a.freq == b.freq && a.core > b.core) return 1; return 0; } long long dp[2][50 * 4001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> pc1[i].core >> pc1[i].freq >> pc1[i].value; a[i] = {pc1[i].core, pc1[i].freq, -pc1[i].value}; } int m; cin >> m; for (int i = 1; i <= m; i++) { cin >> pc2[i].core >> pc2[i].freq >> pc2[i].value; a[n + i] = {-pc2[i].core, pc2[i].freq, pc2[i].value}; } int l = n + m; sort(a + 1, a + l + 1, csort); for (int i = 0; i <= 1; i++) for (int j = 0; j <= l * 50; j++) dp[i][j] = -1e18; dp[0][0] = 0; for (int i = 1; i <= l; i++) { for (int j = 0; j <= l * 50; j++) dp[i % 2][j] = dp[1 - i % 2][j]; for (int j = 0; j <= l * 50; j++) if (j - a[i].core >= 0 && j - a[i].core <= l * 50) dp[i % 2][j] = max(dp[i % 2][j], dp[1 - i % 2][j - a[i].core] + a[i].value); } long long Max = 0; for (int i = 0; i <= l * 50; i++) Max = max(Max, dp[l % 2][i]); cout << Max << '\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...