이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define int long long
const int inf = 1e18;
const int maxn = 100'001;
int dp[maxn];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<pair<int, int>, pair<int, int>>> vv;
for (int i = 0; i < n; ++i) {
int c, f, v;
cin >> c >> f >> v;
vv.push_back({ { f, -1 }, { v, c } });
}
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int c, f, v;
cin >> c >> f >> v;
vv.push_back({ { f, -2 }, { v, c } });
}
sort(vv.rbegin(), vv.rend());
fill(dp, dp + maxn, -inf);
dp[0] = 0;
for (pair<pair<int, int>, pair<int, int>> x : vv) {
auto [p, q] = x;
auto [f, t] = p;
auto [v, c] = q;
if (t == -1) {
for (int j = maxn - 1; j >= c; --j) {
dp[j] = max(dp[j - c] - v, dp[j]);
}
} else {
for (int j = 0; j + c < maxn; ++j) {
dp[j] = max(dp[j], dp[j + c] + v);
}
}
}
cout << *max_element(dp, dp + maxn);
}
# | 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... |