이 제출은 이전 버전의 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.rbegin(), t.rend());
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++) {
ndp[i + c] = max(ndp[i + c], dp[i] + v);
}
} else {
for (int i = c; i < s; i++) {
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... |