이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |