이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
void testCase() {
int n, m;
cin >> n;
vector<tuple<int, int, int>> t;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
t.push_back({f, c, -v});
}
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
t.push_back({f, c, v});
}
sort(t.begin(), t.end(), [&](tuple<int, int, int> a, tuple<int, int, int> b) {
if (get<0> (a) != get<0> (b)) return get<0> (a) > get<0> (b);
return get<2> (a) < get<2> (b);
});
int s = n * 51;
vector<long long> dp(s, -1e18);
vector<long long> ndp;
dp[0] = 0;
for (auto [f, c, v] : t) {
ndp = dp;
if (v < 0) {
for (int i = 0; i + c < s; i++) {
if (dp[i] != -1e18) ndp[i + c] = max(ndp[i + c], dp[i] + v);
}
} else {
for (int i = c; i < s; i++) {
if (dp[i] != -1e18) ndp[i - c] = max(ndp[i - c], dp[i] + v);
}
}
dp = ndp;
}
cout << *max_element(dp.begin(), dp.end()) << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
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... |