이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1e18;
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, (int) 1e5> evnt;
arr<arr<int, MX_C>, 2> dp;
void cmp() {
for (int c = 1; c <= 1e5; c++) dp[0][c] = -INF;
dp[0][0] = 0;
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... |