제출 #702899

#제출 시각아이디문제언어결과실행 시간메모리
702899VladPislaruCloud Computing (CEOI18_clo)C++17
100 / 100
733 ms1984 KiB
#include <bits/stdc++.h> using namespace std; int n, m; struct Elem { int cores, frecv; long long value; bool operator < (const Elem A) const { if (frecv == A.frecv) return value < A.value; return frecv > A.frecv; } }; Elem a[4005]; long long dp1[200005], dp2[200005]; int main() { cin >> n; int sum_c = 0; for (int i = 1; i <= n; i++) { int c, f, v; cin >> c >> f >> v; a[i] = {c, f, -v}; sum_c += c; } cin >> m; for (int i = 1; i <= m; i++) { int c, f, v; cin >> c >> f >> v; a[n + i] = {-c, f, v}; } n = m + n; sort(a + 1, a + n + 1); for (int i = 0; i <= sum_c; i++) dp1[i] = LLONG_MIN; dp1[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= sum_c; j++) dp2[j] = dp1[j]; for (int j = 0; j <= sum_c; j++) if (dp1[j - a[i].cores] != LLONG_MIN && j - a[i].cores <= sum_c && j - a[i].cores >= 0) { dp2[j] = max(dp2[j], dp1[j - a[i].cores] + a[i].value); } for (int j = 0; j <= sum_c; j++) dp1[j] = dp2[j]; } long long ans = 0; for (int i = 0; i <= sum_c; i++) ans = max(ans, dp1[i]); cout << ans << "\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...