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/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = 1e18 + 100;
const int N = 1e5 + 10;
int main() {
fast;
vector<tuple<int, int, int>> a;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.emplace_back(f, c, v);
}
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.emplace_back(f, -c, v);
}
sort(all(a));
reverse(all(a));
ll d[N];
d[0] = 0;
for (int i = 1; i < N; ++i)
d[i] = -INF;
for (auto [f, c, v]: a) {
if (c > 0) {
for (int i = N - 1; i >= c; --i)
d[i] = max(d[i], d[i - c] - v);
}
else {
for (int i = -c; i < N; ++i)
d[i + c] = max(d[i + c], d[i] + v);
}
}
ll ans = 0;
for (int i = 0; i < N; ++i)
ans = max(ans, d[i]);
cout << ans << '\n';
}
# | 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... |