이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 MAX_C = 201;
const int INF = 1e15;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N;
vector<node> pc(N);
for (int i = 0; i < N; i++)
{
int c, f, v;
cin >> c >> f >> v;
pc[i] = {c, f, v};
}
cin >> M;
vector<node> qr(M);
for (int i = 0; i < M; i++)
{
int c, f, v;
cin >> c >> f >> v;
qr[i] = {c, f, v};
}
sort(pc.begin(), pc.end(), [&](node &a, node &b)
{ if(a.f == b.f) return a.c > b.c; return a.f > b.f; });
sort(qr.begin(), qr.end(), [&](node &a, node &b)
{ if(a.f == b.f) return a.c > b.c; return a.f > b.f; });
int dp[2][N + 1][MAX_C];
for (int i = 0; i < 2; i++)
for (int j = 0; j <= N; j++)
for (int c = 0; c < MAX_C; c++)
dp[i][j][c] = -INF;
int cur = 0, nxt = 1;
dp[0][0][0] = 0;
int mx = 0;
for (int i = 0; i <= M; i++)
{
for (int j = 0; j <= N; j++)
{
for (int c = MAX_C - 1; c >= 0; c--)
{
if (dp[cur][j][c] == -INF)
continue;
// skip zakazku
if (i + 1 <= M)
{
dp[nxt][j][c] = max(dp[nxt][j][c], dp[cur][j][c]);
mx = max(mx, dp[nxt][j][c]);
}
if (j + 1 <= N)
{
// skip pc
dp[cur][j + 1][c] = max(dp[cur][j + 1][c], dp[cur][j][c]);
mx = max(mx, dp[cur][j + 1][c]);
}
// take cores
if (j + 1 <= N && i < M && qr[i].f <= pc[j].f && c + pc[j].c < MAX_C)
{
dp[cur][j + 1][c + pc[j].c] = max(dp[cur][j + 1][c + pc[j].c], dp[cur][j][c] - pc[j].v);
mx = max(mx, dp[cur][j + 1][c + pc[j].c]);
}
// // take next
// if (qr[i].f <= pc[j].f && qr[i].c <= c + pc[j].c)
// {
// dp[nxt][j + 1][c + pc[j].c - qr[i].c] = max(dp[nxt][j + 1][c + pc[j].c - qr[i].c], dp[cur][j][c] + (qr[i].v - pc[j].v));
// mx = max(mx, dp[nxt][j + 1][c + pc[j].c - qr[i].c]);
// }
// take using c
if (i < M && qr[i].c <= c)
{
dp[nxt][j][c - qr[i].c] = max(dp[nxt][j][c - qr[i].c], dp[cur][j][c] + qr[i].v);
mx = max(mx, dp[nxt][j][c - qr[i].c]);
}
}
}
swap(cur, nxt);
for (int j = 0; j <= N; j++)
for (int c = 0; c < MAX_C; c++)
dp[nxt][j][c] = -INF;
}
cout << mx << endl;
}
# | 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... |