제출 #1019505

#제출 시각아이디문제언어결과실행 시간메모리
1019505aufanCloud Computing (CEOI18_clo)C++17
100 / 100
258 ms1372 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int inff = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<array<int, 4>> a; for (int i = 0; i < n; i++) { int c, f, v; cin >> c >> f >> v; a.push_back({c, f, v, 0}); } int m; cin >> m; for (int i = 0; i < m; i++) { int c, f, v; cin >> c >> f >> v; a.push_back({c, f, v, 1}); } sort(a.begin(), a.end(), [&](auto x, auto y) { if (x[1] == y[1]) return x[3] < y[3]; return x[1] > y[1]; }); vector<int> dp(50 * n + 1, -inff); dp[0] = 0; for (auto [c, f, v, t] : a) { if (t == 0) { for (int i = 50 * n; i - c >= 0; i--) { dp[i] = max(dp[i], dp[i - c] - v); } } else if (t == 1) { for (int i = 0; i + c <= 50 * n; i++) { dp[i] = max(dp[i], dp[i + c] + v); } } } int ans = 0; for (int i = 0; i <= 50 * n; i++) ans = max(ans, dp[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...