This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI18_clo"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 2000 + 1;
const int C = 50 + 1;
int n, m;
int c1[N], f1[N], v1[N], a[N];
int c2[N], f2[N], v2[N], b[N];
ll dp[N * C];
void enter(){
cin >> n;
FORU(i, 1, n){
cin >> c1[i] >> f1[i] >> v1[i];
a[i] = i;
}
sort(a + 1, a + n + 1, [&](const int &i, const int &j){
return f1[i] < f1[j];
}
);
cin >> m;
FORU(i, 1, m){
cin >> c2[i] >> f2[i] >> v2[i];
b[i] = i;
}
sort(b + 1, b + m + 1, [&](const int &i, const int &j){
return f2[i] < f2[j];
}
);
}
void buy(int x){
FORD(i, 50 * n, 0) if(c1[a[x]] <= i){
dp[i] = min(dp[i], dp[i - c1[a[x]]] + v1[a[x]]);
} else break;
}
void use(int x){
FORU(i, 0, 50 * n) if(i + c2[b[x]] <= 50 * n){
dp[i] = min(dp[i], dp[i + c2[b[x]]] - v2[b[x]]);
} else break;
}
void solve(){
FORU(i, 1, 50 * n) dp[i] = 1e9;
int i = n, j = m;
for(; i >= 1 && j >= 1; ){
if(f1[a[i]] >= f2[b[j]]){
int ii = i;
while(ii >= 1 && f1[a[ii]] == f1[a[i]]){
// cout << a[ii] << " ";
buy(ii--);
}
// cout << "| a\n";
i = ii;
} else{
int jj = j;
while(jj >= 1 && f2[b[jj]] == f2[b[j]]){
// cout << b[jj] << " ";
use(jj--);
}
// cout << "| b\n";
j = jj;
}
// FORU(k, 0, 20) cout << dp[k] << " ";
// cout << '\n';
}
while(j >= 1) use(j--);
ll ans = 0;
FORU(i, 0, 50 * n) ans = min(ans, dp[i]);
cout << -ans;
}
int main(){
IOS;
Fi();
enter();
solve();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'void Fi()':
clo.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".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... |