This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |