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;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int32_t n; cin >> n;
enum { BUY, SELL };
vector<tuple<int32_t, bool, int32_t, int32_t>> a;
for (int32_t i = 0; i < n; i++) {
int32_t c, f, v; cin >> c >> f >> v;
a.emplace_back(-f, BUY, c, v);
}
int32_t m; cin >> m;
for (int32_t i = 0; i < m; i++) {
int32_t c, f, v; cin >> c >> f >> v;
a.emplace_back(-f, SELL, c, v);
}
sort(a.begin(), a.end());
constexpr int32_t MAX_CORES = 100'000;
constexpr int64_t INF = 1e15;
vector<int64_t> dp(MAX_CORES + 1, -INF);
dp[0] = 0;
for (auto [f, type, c, v] : a) {
auto nxt = dp;
for (int32_t cores = 0; cores <= MAX_CORES; cores++) {
if (type == BUY && cores >= c) {
nxt[cores] = max(dp[cores], dp[cores - c] - v);
} else if (type == SELL && cores + c <= MAX_CORES) {
nxt[cores] = max(dp[cores], dp[cores + c] + v);
}
}
swap(nxt, dp);
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
return 0;
}
# | 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... |