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 ll long long
#define pii pair<int, int>
#define endl '\n'
#define int ll
using namespace std;
struct node
{
int c, f, v;
};
const int INF = 1e15;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N;
vector<node> vals;
int MX_C = 0;
for (int i = 0; i < N; i++)
{
int c, f, v;
cin >> c >> f >> v;
vals.push_back({c, f, -v});
MX_C += c;
}
cin >> M;
for (int i = 0; i < M; i++)
{
int c, f, v;
cin >> c >> f >> v;
vals.push_back({-c, f, v});
}
sort(vals.begin(), vals.end(), [&](node &a, node &b)
{ if(a.f == b.f) return a.c > b.c; return a.f > b.f; });
MX_C++;
int dp[2][MX_C];
fill_n(&dp[0][0], 2 * MX_C, -INF);
dp[0][0] = 0;
int mx = 0, prev = 0, cur = 1;
for (int i = 0; i < vals.size(); i++)
{
for (int c = MX_C - 1; c >= 0; c--)
{
dp[cur][c] = dp[prev][c];
int cores = c - vals[i].c;
if (0 <= cores && cores < MX_C)
{
dp[cur][c] = max(dp[prev][cores] + vals[i].v, dp[cur][c]);
mx = max(mx, dp[cur][c]);
}
}
swap(cur, prev);
}
cout << mx << endl;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:53:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < vals.size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |