제출 #580616

#제출 시각아이디문제언어결과실행 시간메모리
580616tengiz05Cloud Computing (CEOI18_clo)C++17
100 / 100
405 ms1236 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; constexpr int N = 100000; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<array<int, 3>> a; for (int i = 0; i < n; i++) { int c, f, v; cin >> c >> f >> v; a.push_back({c, f, -v}); } 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}); } sort(a.begin(), a.end()); vector<i64> dp(N + 1, -1E15); dp[0] = 0; sort(a.begin(), a.end(), [&](const array<int, 3> &a, const array<int, 3> &b) { if (a[1] == b[1]) return a[2] < b[2]; return a[1] > b[1]; }); for (auto [c, f, v] : a) { if (v < 0) { for (int i = N; i >= c; i--) { dp[i] = max(dp[i], dp[i - c] + v); } } else { for (int i = c; i <= N; i++) { dp[i - c] = max(dp[i - c], dp[i] + v); } } } i64 ans = *max_element(dp.begin(), dp.end()); 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...