제출 #843090

#제출 시각아이디문제언어결과실행 시간메모리
843090asdfgraceCloud Computing (CEOI18_clo)C++17
72 / 100
484 ms1368 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); const int mx = 100005; int n; cin >> n; vector<array<int, 3>> a(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { cin >> a[i][j]; } a[i][2] = -a[i][2]; } int m; cin >> m; a.resize(n + m); for (int i = 0; i < m; ++i) { for (int j = 0; j < 3; ++j) { cin >> a[i + n][j]; } a[i + n][0] = -a[i + n][0]; } sort(a.begin(), a.end(), [&] (array<int, 3> a1, array<int, 3> a2) { return a1[1] > a2[1]; }); vector<long long> dp(mx, -1e18); dp[0] = 0; for (int i = 0; i < n + m; ++i) { if (a[i][0] > 0) { for (int j = mx - a[i][0] - 1; j >= 0; --j) { if (dp[j] == -1e18) continue; dp[j + a[i][0]] = max(dp[j + a[i][0]], dp[j] + a[i][2]); } } else { for (int j = -a[i][0]; j < mx; ++j) { if (dp[j] == -1e18) continue; dp[j + a[i][0]] = max(dp[j + a[i][0]], dp[j] + a[i][2]); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; }
#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...