이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define cll const ll
#define lp(a, b, c) for(ll a = b; a <= c; ++a)
#define lpd(a, b, c) for(ll a = b; a >= c; --a)
#define vec(a) vector<a>
#define pp(a, b) pair<a, b>
#define EACHCASE lpd(cs, read(), 1)
#define Fname "f"
using namespace std;
void giuncute(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void OF(){
freopen(Fname".inp", "r", stdin);
freopen(Fname".out", "w", stdout);
}
cll mxn = 2e3 + 1;
ll n, m, dp[2][mxn * 50 * 2] = {{0}}, ans = 0;
struct obj{
ll c, f, v;
bool type;
obj(ll _c, ll _f, ll _v, bool _type) : c(_c), f(_f), v(_v), type(_type) {}
obj(){}
}a[mxn * 2];
bool cpr(obj &u, obj &v){
return u.f != u.v ? u.f > v.f : u.type < v.type;
}
int main(){
giuncute();
cin >> n;
lp(i, 1, n){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].type = 0;
}
cin >> m;
lp(i, n + 1, n + m){
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].type = 1;
}
sort(a + 1, a + n + m + 1, cpr);
lp(i, 1, (n + m) * 50) dp[0][i] = -1e18;
lp(i, 1, n + m) lp(j, 0, (n + m) * 50){
dp[i & 1][j] = dp[~i & 1][j];
if(a[i].type){ // rent
if(j + a[i].c <= n * 50) dp[i & 1][j] = max(dp[i & 1][j], dp[~i & 1][j + a[i].c] + a[i].v);
} else{
if(j - a[i].c >= 0) dp[i & 1][j] = max(dp[i & 1][j], dp[~i & 1][j - a[i].c] - a[i].v);
}
ans = max(ans, dp[i & 1][j]);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void OF()':
clo.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen(Fname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(Fname".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... |