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>
#define int long long
using namespace std;
const int MAX = 2000 * 50;
int DP[2][MAX + 10];
int32_t main()
{
vector<array<int, 3>> items;
int k1;
cin >> k1;
for (int i = 0; i < k1; i++)
{
int c, f, v;
cin >> c >> f >> v;
items.push_back({f, c, -v});
}
int k2;
cin >> k2;
for (int i = 0; i < k2; i++)
{
int c, f, v;
cin >> c >> f >> v;
items.push_back({f, -c, v});
}
sort(items.rbegin(), items.rend());
memset(DP, -0x3f, sizeof DP);
int ans = 0;
DP[0][0] = 0;
bool s = 0;
for (auto [f, c, v] : items)
{
s = !s;
for (int i = 0; i <= MAX; i++)
{
DP[s][i] = DP[!s][i];
if (i - c <= MAX && i - c >= 0) DP[s][i] = max(DP[s][i], DP[!s][i - c] + v);
ans = max(ans, DP[s][i]);
}
}
cout << ans;
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... |