이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2e3 + 5;
const int oo = 1e18, mod = 1e9 + 7;
int n, m, CORE, ans = 0;
vector<array<int, 4>> q;
vector<int> dp(N * 50 + 100, -oo);
void process() {
cin >> n;
foru(i, 1, n) {
int c, f, v;
cin >> c >> f >> v;
q.pb({f, 1ll, c, -v});
}
cin >> m;
foru(i, 1, m) {
int C, F, V;
cin >> C >> F >> V;
q.pb({F, 0ll, C, V});
}
CORE = 50 * n + 1;
dp[0] = 0ll;
sort(q.rbegin(), q.rend());
for (auto cmp : q) {
if (cmp[1]) {
ford(i, CORE, cmp[2]) {
dp[i] = max(dp[i], dp[i - cmp[2]] + cmp[3]);
}
} else {
foru(i, 0, CORE) {
dp[i] = max(dp[i], dp[i + cmp[2]] + cmp[3]);
}
}
}
for (auto x : dp) ans = max(ans, x);
cout << max(0ll, ans) << '\n';
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
# | 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... |