이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define int long long
#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];
void debug()
{
if (0)
for (int i = 1; i <= mxsize; i++)
cout << dp[i] << " \n"[i == mxsize];
}
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)
{
if (p1.f != p2.f)
return p1.f < p2.f;
return p1.c < p2.c ;
});
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);
debug();
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;
ll idx2 = lower_bound(computer, computer + 1 + N,
P(0, order[i].f, 0), [](P p1, P p2)
{ return p1.f < p2.f; }) -
computer;
for (int j = mxsize; j >= idx + order[i].c; j--)
dp[j] = max({dp[j], dp[j - order[i].c] + order[i].v});
debug();
for (int j = 1; j <= mxsize; j++)
dp[j] = max(dp[j], dp[j - 1]);
debug();
for (int j = idx2; j <= N; j++)
dp[computer[j].c] = max(dp[computer[j].c], dp[computer[j - 1].c] + computer[j].v);
debug();
for (int j = 1; j <= mxsize; j++)
dp[j] = max(dp[j], dp[j - 1]);
debug();
}
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... |