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(false);
cin.tie(0);
int n, m, s = 0;
cin >> n;
vector<array<int, 4>> a(n);
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
a[i] = {-f, 0, c, -v};
s += c;
}
cin >> m;
a.resize(n + m);
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
a[i + n] = {-f, 1, -c, v};
}
sort(a.begin(), a.end());
const int inf = (int) 1e9 + 9;
vector<int> dp(s + 51, -inf);
dp[0] = 0;
vector<int> pd(s + 51);
for (int i = 0; i < n + m; i++) {
int c = a[i][2], v = a[i][3];
pd = dp;
for (int j = max(c, 0); j <= s; j++) {
pd[j] = max(pd[j], dp[j - c] + v);
}
swap(dp, pd);
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
return 0;
}
# | 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... |