이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, p;
node(int x = 0, int y = 0, int z = 0, int p = 0) : x(x), y(y), z(z), p(p) {}
};
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, p] = a[i];
cin >> x >> y >> z;
tot += x;
p = i;
}
cin >> M;
for(int i = N + 1; i <= N + M; i++) {
auto &[x, y, z, p] = a[i];
cin >> x >> y >> z;
p = i;
}
sort(a + 1, a + N + M + 1, [&](const node a, const node b) {
if(a.y != b.y) return a.y > b.y;
return a.p < b.p;
});
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, p] = a[i];
if(p <= N) {
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);
}
컴파일 시 표준 에러 (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... |