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 per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1000000007;
int main() {
int n, m, c, sumc = 1;
vector<pair<ii, pair<ll, int>>> dpvec;
ll f, v, ans = 0;
cin >> n;
rep(i, 0, n) {
scanf("%d %lld %lld", &c, &f, &v);
dpvec.push_back({{f, 1}, {v, c}});
sumc += c;
}
cin >> m;
rep(i, 0, m) {
scanf("%d %lld %lld", &c, &f, &v);
dpvec.push_back({{f, 0}, {v, c}});
}
sort(all(dpvec), greater<>());
ll memo[2][sumc];
bool curr = 0, next = 1;
fill(memo[0], memo[0] + sumc, -1e15);
fill(memo[1], memo[1] + sumc, -1e15);
memo[0][0] = 0;
trav(item, dpvec) {
int query;
tie(f, query) = item.first;
tie(v, c) = item.second;
rep(i, 0, sumc) {
if (memo[curr][i] == -1e15) continue;
memo[next][i] = max(memo[next][i], memo[curr][i]);
if (query)
memo[next][i + c] = max(memo[next][i + c], memo[curr][i] - v);
else if (!query && c <= i)
memo[next][i - c] = max(memo[next][i - c], memo[curr][i] + v);
}
swap(curr, next);
fill(memo[next], memo[next] + sumc, -1e15);
}
rep(i, 0, sumc) ans = max(ans, memo[curr][i]);
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
32 | scanf("%d %lld %lld", &c, &f, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d %lld %lld", &c, &f, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |