이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL INF = 1000000000000000000LL;
int n, m, c[2005], f[2005], v[2005], C[2005], F[2005], V[2005];
LL dp[2][200005];
pair<PII, int> ord[4005];
int main()
{
scanf("%d", &n);
rep(i, n) {
scanf("%d%d%d", &c[i], &f[i], &v[i]);
ord[i] = MP(MP(-f[i], 0), i);
}
scanf("%d", &m);
rep(i, m) {
scanf("%d%d%d", &C[i], &F[i], &V[i]);
ord[i + n] = MP(MP(-F[i], 1), i);
}
sort(ord, ord + n + m);
rep(i, 2) rep(j, n * 51) dp[i][j] = -INF;
dp[1][0] = 0;
rep(i, n + m) {
int ii = ((i & 1) ^ 1);
int id = ord[i].second;
rep(j, n * 51) dp[i & 1][j] = dp[ii][j];
if(ord[i].first.second == 0) {
for(int j = n * 51 - 1; j >= c[id]; j--) {
dp[i & 1][j] = max(dp[i & 1][j], dp[ii][j - c[id]] - v[id]);
}
} else {
for(int j = n * 51 - 1; j >= C[id]; j--) {
dp[i & 1][j - C[id]] = max(dp[i & 1][j - C[id]], dp[ii][j] + V[id]);
}
}
}
LL ans = 0;
rep(i, 2) rep(j, n * 51) ans = max(ans, dp[i][j]);
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
clo.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d%d%d", &c[i], &f[i], &v[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
clo.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d%d%d", &C[i], &F[i], &V[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |