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;
struct Transaction
{
uint64_t f;
int64_t c, v;
bool operator<(Transaction const &t) const
{
if (f == t.f)
return v < 0 && !(t.v < 0);
return f > t.f;
}
};
#define N 4000
#define C 51
Transaction t[N];
int64_t dp[N * C];
int main()
{
size_t n, l = 0;
cin >> n;
for (size_t i = 0; i < n; i++)
{
cin >> t[l].c >> t[l].f >> t[l].v;
t[l].v = -t[l].v;
l++;
}
size_t m;
cin >> m;
for (size_t i = 0; i < m; i++)
{
cin >> t[l].c >> t[l].f >> t[l].v;
t[l].c = -t[l].c;
l++;
}
sort(t, t + l);
fill(dp + 1, dp + N * C, INT64_MIN);
for (size_t i = 0; i < l; i++)
{
auto const &[f, c, v] = t[i];
if (c < 0)
{
for (int64_t j = -c; j < N * C; j++)
if (dp[j] != INT64_MIN)
dp[j + c] = max(dp[j + c], dp[j] + v);
}
else
{
for (int64_t j = N * C - c - 1; j >= 0; j--)
if (dp[j] != INT64_MIN)
dp[j + c] = max(dp[j + c], dp[j] + v);
}
}
int64_t max_value = 0;
for (size_t i = 0; i < N * C; i++)
max_value = max(max_value, dp[i]);
cout << max_value << '\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... |