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;
using ll = long long;
struct NODE {
ll w;
ll f;
ll v;
bool operator<(const NODE& b) {
if (this->f == b.f) return this->w > b.w;
return this->f > b.f;
}
};
const ll MAXW = 4000 * 50 + 100;
void solve() {
ll N, M;
vector<NODE> a;
cin >> N;
for (int i = 0; i < N; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({c, f, -v});
}
cin >> M;
for (int i = 0; i < M; i++) {
ll c, f, v;
cin >> c >> f >> v;
a.push_back({-c, f, v});
}
sort(a.begin(), a.end());
//for (auto x : a) cout << x.w << " " << x.v << endl;
ll n = a.size();
ll dp[2][MAXW];
for (int i = 0; i < MAXW; i++) dp[0][i] = -1e18;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
ll v = a[i-1].v;
ll w = a[i-1].w;
int cur = i%2;
int prev = !cur;
for (int j = MAXW-1; j >= 0; j--) {
dp[cur][j] = dp[prev][j];
if (j - w >= 0 && j - w < MAXW && dp[prev][j - w] != -1e18) dp[cur][j] = max(dp[cur][j], dp[prev][j - w] + v);
}
}
ll ans = 0;
for (int i = 0; i < MAXW; i++) ans = max(ans, dp[n%2][i]);//cout << x << " "; cout << endl;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--) solve();
}
# | 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... |