이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"
using namespace std;
const int N = 2e3 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}
struct item{
int c, f, v;
bool operator<(const item &other) const {
return f > other.f;
}
};
int n;
int m;
item a[N];
item b[N];
ll f[2][N][105];
void load(){
cin.tie(0)->sync_with_stdio(0);
if (fopen(name".inp", "r")){
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
void input(){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].c >> a[i].f >> a[i].v;
cin >> m;
for (int i = 1; i <= m; i++) cin >> b[i].c >> b[i].f >> b[i].v;
}
void solve(){
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
mem(f, -0x3f);
f[0][0][0] = 0;
for (int i = 1; i <= n; i++){
int cur = i & 1;
int pre = cur ^ 1;
f[cur][0][0] = 0;
for (int k = 100; k >= 0; k--){
maxi(f[cur][0][k], f[pre][0][k]);
maxi(f[cur][0][k], f[cur][0][k + 1]);
if (k >= a[i].c) maxi(f[cur][0][k], f[pre][0][k - a[i].c] - a[i].v);
}
for (int j = 1; j <= m; j++){
for (int k = 100; k >= 0; k--){
maxi(f[cur][j][k], f[pre][j][k]);
maxi(f[cur][j][k], f[cur][j - 1][k]);
maxi(f[cur][j][k], f[cur][j][k + 1]);
if (k >= a[i].c)
maxi(f[cur][j][k], f[pre][j - 1][k - a[i].c] - a[i].v);
if (b[j].f <= a[i].f && k >= b[j].c){
maxi(f[cur][j][k - b[j].c], f[cur][j - 1][k] + b[j].v);
}
}
}
mem(f[pre], -0x3f);
}
cout << f[n & 1][m][0];
}
int main(){
load();
input();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void load()':
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(name".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(name".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... |