Submission #1019996

#TimeUsernameProblemLanguageResultExecution timeMemory
1019996michifiedCloud Computing (CEOI18_clo)C++17
100 / 100
646 ms2192 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; struct spec_t { int c, s; ll v; }; int main() { int n, m, i, j, ccnt = 0; cin >> n; vector<spec_t> specs; for (i = 0; i < n; i++) { specs.push_back({0, 0, 0}); cin >> specs[i].c >> specs[i].s >> specs[i].v; ccnt += specs[i].c; specs[i].v = -specs[i].v; } cin >> m; for (i = n; i < m + n; i++) { specs.push_back({0, 0, 0}); cin >> specs[i].c >> specs[i].s >> specs[i].v; specs[i].c = -specs[i].c; } specs.push_back({0, INT_MAX, 0}); sort(specs.begin(), specs.end(), [](const spec_t& a, const spec_t& b){return a.s == b.s ? a.v < b.v : a.s > b.s;}); int t = n + m + 1; vector<ll> dp1(ccnt + 1, LLONG_MIN); dp1[0] = 0; for (i = 1; i < t; i++) { vector<ll> dp2 = dp1; for (j = 0; j <= ccnt; j++) { int prev = j - specs[i].c; if (prev >= 0 and prev <= ccnt and dp1[prev] != LLONG_MIN) dp2[j] = max(dp2[j], dp1[prev] + specs[i].v); } swap(dp1, dp2); } cout << *max_element(dp1.begin(), dp1.end()); 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...