#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
const int mxc = 1e5 + 10;
struct S {
ll c, f, v;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<S> a;
for (int i = 0; i < n; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({c, f, -v});
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({-c, f, v});
}
sort(all(a), [&] (S f, S s) {
return (f.f == s.f ? f.v < s.v : f.f > s.f);
});
vector<ll> dp(mxc, -2e17), newDp(mxc);
dp[0] = 0;
for (auto x : a) {
newDp = dp;
for (int i = 0; i < mxc; i++) {
if (i - x.c >= 0 && i - x.c < mxc && dp[i - x.c] != -2e17) newDp[i] = max(newDp[i], dp[i - x.c] + x.v);
}
dp = newDp;
}
cout << *max_element(all(dp));
}
# | 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... |