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 rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
ll n; cin >> n;
vector<tuple<ll,ll,ll>> v(n);
for(ll i = 0; i < n; i++){
ll a, b, c;
cin >> a >> b >> c;
v[i] = {b, c, a};
}
ll k; cin >> k;
vector<tuple<ll,ll,ll>> s(k);
for(ll i = 0; i < k; i++){
ll a, b, c;
cin >> a >> b >> c;
s[i] = {b, c, a};
}
sort(all(v)); sort(all(s));
ll dp[55], ans;
const ll INF = 1e15;
ans = -INF;
for(ll i = 0; i < 55; i++) dp[i] = -INF;
dp[0] = 0;
ll curr = n-1;
for(ll i = k-1; i >= 0; i--){
for(ll j = curr; j >= 0; j--){
ll a1, a2, b1, b2, c1, c2;
tie(b1, c1, a1) = s[i];
tie(b2, c2, a2) = v[j];
if(b1 > b2){ curr--; break; }
//cout << a1 << ' ' << b1 << ' ' << c1 << ' ' << a2 << ' ' << b2 << ' ' << c2 << '\n';
for(ll l = 51; l >= 0; l--){
if(l-a2>=0) dp[l] = max(dp[l], max(dp[l-a2] - c2, dp[l-1]));
ans = max(ans, dp[l]);
}
for(ll l = 0; l < 51-a1; l++){
if(dp[l+a1] > -INF) dp[l] = max(dp[l], max(dp[l+a1] + c1, dp[l-1]));
//if(i==k-1) cout << l << ' ' << dp[l] << ' ' << dp[l+a1] << '\n';
ans = max(ans, dp[l]);
}
curr = j;
}
}
cout << ans << '\n';
}
Compilation message (stderr)
clo.cpp: In function 'void usaco(std::string)':
clo.cpp:12:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
12 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
13 | 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... |