이 제출은 이전 버전의 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 = 250 + 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[N][N][N];
ll btr(int i, int j, int rem){
if (i > n || j > m) return 0;
ll &res = f[i][j][rem];
if (res >= -oo) return res;
res = -oo;
maxi(res, btr(i + 1, j, rem));
maxi(res, btr(i, j + 1, rem));
maxi(res, btr(i + 1, j, rem + a[i].c) - a[i].v);
if (b[j].f <= a[i - 1].f && rem >= b[j].c){
maxi(res, btr(i, j + 1, rem - b[j].c) + b[j].v);
}
return res;
}
void solve(){
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
mem(f, -0x3f);
cout << btr(1, 1, 0);
}
}
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... |