This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type,
less<ll>, rb_tree_tag,
tree_order_statistics_node_update> oset;
mt19937_64 gen(time(0));
const ll N = 5007, M = 1000007;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll m;
cin >> m;
vector<pair<ll,ll>> all;
ll c[m], f[m], v[m];
for(int i = 0; i < m; i++) {
cin >> c[i] >> f[i] >> v[i];
all.pb({f[i], i + 1});
}
ll n;
cin >> n;
ll c2[n], f2[n], v2[n];
for(int i = 0; i < n; i++) {
cin >> c2[i] >> f2[i] >> v2[i];
all.pb({f2[i], -(i + 1)});
}
ll cost[m * 50 + 1];
for(int i = 0; i < m * 50 + 1; i++) {
cost[i] = -1e18;
}
cost[0] = 0;
ll sum = 0;
sort(all.rbegin(), all.rend());
for(auto to: all) {
if(to.s > 0) {
ll x = to.s - 1;
sum += c[x];
for(int i = sum; i >= c[x]; i--) {
cost[i] = max(cost[i], cost[i - c[x]] - v[x]);
}
} else {
ll x = (-to.s - 1);
for(int i = 0; i <= sum - c2[x]; i++) {
cost[i] = max(cost[i + c2[x]] + v2[x], cost[i]);
}
}
for(int i = sum - 1; i >= 0; i--) {
cost[i] = max(cost[i], cost[i + 1]);
}
}
cout << cost[0] << '\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... |