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;
using i64 = long long;
const i64 oo64 = 1e15;
const int MAXN = 2e5 + 5;
struct node {
int x, y, z, type;
node(int x = 0, int y = 0, int z = 0, int type = 0) : x(x), y(y), z(z), type(type) {}
};
int N, M;
node a[MAXN];
i64 dp[MAXN];
int tot = 0;
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for(int i = 1; i <= N; i++) {
auto &[x, y, z, type] = a[i];
cin >> x >> y >> z;
tot += x;
type = 0;
}
cin >> M;
for(int i = N + 1; i <= N + M; i++) {
auto &[x, y, z, type] = a[i];
cin >> x >> y >> z;
type = 1;
}
sort(a + 1, a + N + M + 1, [&](const node a, const node b) {
return a.y > b.y;
});
for(int i = 1; i <= tot; i++) dp[i] = -oo64;
dp[0] = 0;
for(int i = 1; i <= N + M; i++) {
const auto [x, y, z, type] = a[i];
if(type == 0) {
for(int j = tot; j >= x; j--)
dp[j] = max(dp[j], dp[j - x] - z);
} else {
for(int j = 0; j <= tot - x; j++)
dp[j] = max(dp[j], dp[j + x] + z);
}
}
cout << *max_element(dp + 1, dp + tot + 1);
return (0 ^ 0);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(TASK ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(TASK ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |