이 제출은 이전 버전의 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 = 1e3 + 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];
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;
}
namespace subtask3{
ll f[2][N][N];
void solve(){
ll ans = 0;
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
int sum = 0;
mem(f, -0x3f);
f[0][0][0] = 0;
for (int i = 1; i <= n; i++){
bool cur = i & 1;
bool pre = cur ^ 1;
for (int j = 0; j <= m; j++){
for (int k = 0; k <= sum; k++){
maxi(f[cur][j][k], f[pre][j][k]);
maxi(f[cur][j][k + a[i].c], f[pre][j][k] - a[i].v);
if (j > 0) maxi(f[cur][j][k], f[cur][j - 1][k]);
maxi(ans, f[cur][j][k]);
}
}
sum += a[i].c;
for (int j = 1; j <= m; j++){
if (b[j].f > a[i].f) continue;
for (int k = 0; k <= sum; k++){
if (k + b[j].c <= sum){
maxi(f[cur][j][k], f[cur][j - 1][k + b[j].c] + b[j].v);
}
maxi(ans, f[cur][j][k]);
}
}
// if (i == 4){
// cout << f[cur][m - 1][1] << '\n';
// }
}
cout << ans;
}
}
int main(){
load();
input();
if (max(n, m) <= 250)
subtask3::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void load()':
clo.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".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... |