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>
#ifdef DEBUG
#include "debug.hpp"
#define debug(x...) \
do { \
++dbg::depth; \
string dbg_vals = dbg::to_string(x); \
--dbg::depth; \
dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
} while (false)
#else
#define debug(...) 42
#endif
using namespace std;
template<typename T> inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T> inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
constexpr int M{50 * 2000};
constexpr long long INF{1LL << 50};
vector<tuple<int, int, int>> a;
int n; cin >> n;
for (int i{}; i < n; ++i) {
int c, f, v; cin >> c >> f >> v;
a.push_back({-f, -v, c});
}
int m; cin >> m;
for (int i{}; i < m; ++i) {
int c, f, v; cin >> c >> f >> v;
a.push_back({-f, v, -c});
}
sort(a.begin(), a.end());
array<long long, M + 1> dp{};
fill(dp.begin() + 1, dp.end(), -INF);
for (auto [_, v, c]: a) {
if (v < 0)
for (int i{M - c}; i >= 0; --i)
ckmax(dp[i + c], dp[i] + v);
if (v > 0)
for (int i{-c}; i <= M; ++i)
ckmax(dp[i + c], dp[i] + v);
}
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... |