이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = n; i <= m; i ++)
#define rrep(i, n, m) for (ll i = n; i >= m; i --)
#define file "test"
using namespace std;
const long long N = 5e3 + 7;
const long long INF = 1e18;
const long long MOD = 2e9 + 11;
const long long base = 311;
ll n, m, dp[2][N];
struct clo {
ll c, f, v, t;
bool operator <(clo other) {
if (f == other.f) {
if (t == other.t)
return v < other.v;
return t < other.t;
}
return f > other.f;
}
} a[N];
void maximize(ll &x, ll y) {
if (y > x) x = y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
#endif // ONLINE_JUDGE
cin >> n;
ll mx = 0;
rep(i, 1, n) {
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].t = 0;
mx += a[i].c;
}
cin >> m;
rep(i, n + 1, m + n) {
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].t = 1;
}
sort(a + 1, a + 1 + n + m);
rep(i, 0, mx) dp[1][i] = dp[0][i] = -INF;
dp[0][0] = 0;
rep(i, 1, n + m) {
ll val = 0, add = 0;
if (a[i].t == 0)
val = -a[i].v, add = a[i].c;
else
val = a[i].v, add = -a[i].c;
rep(j, 0, mx) dp[1][j] = dp[0][j];
rep(j, 0, mx)
if (j + add <= mx && j + add >= 0)
maximize(dp[1][j + add], dp[0][j] + val);
rep(j, 0, mx) dp[0][j] = dp[1][j];
}
ll ans = 0;
rep(i, 0, mx) ans = max(ans, dp[1][i]);
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | freopen(file".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... |