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;
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define bugarr(a, i, j) cout << #a << "{" << i << "..." << j << "}:"; fto(k, i, j-1) cout << a[k] << ", "; cout << a[j] << endl;
#define ll long long
#define db double
#define ldb long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define vt vector
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(i, a) for(auto &i : a)
#define sz(a) (int)a.size()
#define pi(a, b) pair<a, b>
#define fast ios::sync_with_stdio(false); cin.tie(0)
void setIO(string s) {
if (sz(s) != 0) {
freopen((s+".inp").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
}
void setIOusaco(string s) {
if (sz(s) != 0) {
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
}
template<typename T, typename V>
bool ckmin(T &a, V b) {return (b < a)? a = b, true : false;}
template<typename T, typename V>
bool ckmax(T &a, V b) {return (b > a)? a = b, true : false;}
const int maxN = 2004;
ll f[maxN][maxN][53];
int n, m;
array<ll, 3> buy[maxN], sold[maxN];
ll dp(int i, int j, int k) {
assert(k <= 50);
if (j > m) return 0;
if (f[i][j][k] != -1) return f[i][j][k];
if (i > n) {
ll res = dp(i, j+1, k);
if (sold[j][0] <= k) res = max(res, dp(i, j+1, k-sold[j][0])+sold[j][2]);
return f[i][j][k] = res;
}
ll res = max({dp(i+1, j, k), dp(i, j+1, k), 0LL});
if (k >= sold[j][0]) {
res = max(res, dp(i, j+1, k-sold[j][0]) + sold[j][2]);
} else {
if (buy[i][1] >= sold[j][1]) {
if (buy[i][0]+k < sold[j][0]) {
res = max(res, dp(i+1, j, buy[i][0]+k)-buy[i][2]);
} else {
res = max(res, dp(i+1, j+1, buy[i][0]+k-sold[j][0])-buy[i][2]+sold[j][2]);
}
}
}
return f[i][j][k] = res;
}
int main() {
#ifndef TAP
setIO("");
//setIOusaco("CEOI18_clo");
#endif
fast;
cin >> n;
fto(i, 1, n) {
cin >> buy[i][0] >> buy[i][1] >> buy[i][2];
}
sort(buy+1, buy+1+n, [](array<ll, 3> a, array<ll, 3> b){
return a[1] > b[1];
});
cin >> m;
fto(i, 1, m) {
cin >> sold[i][0] >> sold[i][1] >> sold[i][2];
}
sort(sold+1, sold+m+1, [](array<ll, 3> a, array<ll, 3> b) {
return a[1] > b[1];
});
fto(i, 1, n+1) {
fto(j, 1, m) {
fto(k, 0, 50) f[i][j][k] = -1;
}
}
cout << dp(1, 1, 0) << '\n';
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'void setIO(std::string)':
clo.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen((s+".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp: In function 'void setIOusaco(std::string)':
clo.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen((s+".out").c_str(),"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... |