이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
struct vec { int c, f, v; };
bool cmp(const vec& a, const vec& b) { return a.f > b.f; }
const int maxc = 55;
const ll inf = 1e18;
void upd(ll& a, const ll& b) { a = max(a, b); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vec> p(n);
for (int i = 0; i < n; i++) cin >> p[i].c >> p[i].f >> p[i].v;
sort(p.begin(), p.end(), cmp);
int m;
cin >> m;
vector<vec> z(m);
for (int i = 0; i < m; i++) cin >> z[i].c >> z[i].f >> z[i].v;
sort(z.begin(), z.end(), cmp);
vector<vector<vector<ll> > > dp(2, vector<vector<ll>>(m + 1, vector<ll>(maxc * 2, -inf)));
// dp[dalsi pocitac & 1][dalsi zakaznik][pocet pocitacov navyse]
dp[0][0][0] = 0;
ll ans = -inf;
for (int i = 0; i < n; i++)
{
int pv = (i & 1), nw = pv ^ 1;
for (int j = 0; j <= m; j++) for (int c = 0; c < maxc * 2; c++)
dp[nw][j][c] = -inf;
// najprv vyskusame kupit/nekupit novy pocitac
for (int j = 0; j < m; j++) for (int c = 0; c < maxc; c++)
{
upd(dp[nw][j][c], dp[pv][j][c]);
upd(dp[nw][j][c + p[i].c], dp[pv][j][c] - p[i].v);
}
// teraz vyskusame ze predame/nepredame jadra zakaznikovi
for (int j = 0; j < m; j++) for (int c = 0; c < maxc * 2; c++)
{
upd(dp[nw][j + 1][c], dp[nw][j][c]);
if (z[j].c <= c && z[j].f <= p[i].f)
upd(dp[nw][j + 1][c - z[j].c], dp[nw][j][c] + z[j].v);
}
// teraz ideme updatnut ans
for (int j = 0; j <= m; j++) for (int c = 0; c < maxc * 2; c++)
upd(ans, dp[nw][j][c]);
}
cout << ans << "\n";
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... |