This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
struct P
{
ll c, f, v;
P(ll c, ll f, ll v) : c(c), f(f), v(v){};
P() : c(0), f(0), v(0){};
};
ll M, N, dp[100001], cost, mxsize;
P computer[2005], order[2005];
signed main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++)
cin >> computer[i].c >> computer[i].f >> computer[i].v;
sort(computer + 1, computer + 1 + N, [](P p1, P p2)
{ return p1.f < p2.f; });
cin >> M;
for (int i = 1; i <= M; i++)
cin >> order[i].c >> order[i].f >> order[i].v;
sort(order + 1, order + 1 + M, [](P p1, P p2)
{ return p1.f < p2.f; });
for (int i = 1; i <= N; i++)
{
computer[i].c += computer[i - 1].c;
cost += computer[i].v;
}
mxsize = computer[N].c;
for (int j = 1; j <= N; j++)
dp[computer[j].c] = max(dp[computer[j].c], dp[computer[j - 1].c] + computer[j].v);
for (int i = 1; i <= M; i++)
{
ll idx = prev(lower_bound(computer, computer + 1 + N,
P(0, order[i].f, 0), [](P p1, P p2)
{ return p1.f < p2.f; }))
->c;
for (int j = mxsize; j >= idx + order[i].c; j--)
dp[j] = max({dp[j], dp[j - order[i].c] + order[i].v});
for (int j = 1; j <= mxsize; j++)
dp[j] = max(dp[j], dp[j - 1]);
for (int j = 1; j <= N; j++)
dp[computer[j].c] = max(dp[computer[j].c], dp[computer[j - 1].c] + computer[j].v);
for (int j = 1; j <= mxsize; j++)
dp[j] = max(dp[j], dp[j - 1]);
}
cout << dp[mxsize] - cost << '\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... |