This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
const int MX_N = 2e3 + 5, MX_M = 2e3 + 5, MX_C = 1e5 + 5, INF = 1e16;
int n, m;
struct Evnt {
bool is_gn;
int cp, pwr, vl;
bool operator<(Evnt othr) {
if (othr.pwr == pwr) return is_gn;
return pwr > othr.pwr;
}
};
arr<Evnt, MX_N + MX_M> evnt;
// arr<arr<int, MX_C>, 2> dp;
int dp[2][MX_C];
void cmp() {
for (int c = 1; c <= 1e5; c++) dp[0][c] = -INF;
for (int i = 1; i <= n + m; i++) {
int prty = i % 2, opp_prty = (i + 1) % 2;
if (evnt[i].is_gn) {
for (int c = 0; c <= 1e5; c++) {
if (c - evnt[i].cp >= 0) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c - evnt[i].cp] - evnt[i].vl);
else dp[prty][c] = dp[opp_prty][c];
}
} else {
for (int c = 0; c <= 1e5; c++) {
if (c + evnt[i].cp <= 1e5) dp[prty][c] = max(dp[opp_prty][c], dp[opp_prty][c + evnt[i].cp] + evnt[i].vl);
else dp[prty][c] = dp[opp_prty][c];
}
}
}
}
signed main() {
// freopen("cld.in", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
int cp, pwr, vl; cin >> cp >> pwr >> vl;
evnt[i] = {true, cp, pwr, vl};
}
cin >> m;
for (int i = 1; i <= m; i++) {
int cp, pwr, vl; cin >> cp >> pwr >> vl;
evnt[n + i] = {false, cp, pwr, vl};
}
sort(evnt.begin() + 1, evnt.begin() + n + m + 1);
cmp();
int ans = 0;
for (int c = 0; c <= 1e5; c++) ans = max(ans, dp[(n + m) % 2][c]);
cout << ans << endl;
}
# | 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... |