# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941164 | smartmonky | Cloud Computing (CEOI18_clo) | C++14 | 1127 ms | 3676 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// CEOI 2018 - Cloud Computing
// Lúcio Cardoso
// Solution:
// Sort the orders and the computers by their F value. Notice that, if we choose and order j
// and a computer i to be used in such order, any other order with index >= j will use only
// computers of index >= i. Hence, we can use a dp[N][M][C] whose states are the current index of
// a computer (which we can choose to use or not), current index of an order and total amount of
// cores avaliable.
// To reduce the amount of memory used, use the "memory trick" (i.e using dp[2][M][C]).
// Complexity: O(n*m*maxC).
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+10;
const int maxc = 51;
const ll inf = 2e18+10;
struct Obj
{
int c, f, v;
} a[maxn], b[maxn];
int n, m;
ll dp[2][maxn][2*maxc];
void upd(ll &a, ll b)
{
a = max(a, b);
}
bool comp(Obj a, Obj b)
{
return a.f > b.f;
}
int main(void)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d %d %d", &a[i].c, &a[i].f, &a[i].v);
scanf("%d", &m);
for (int i = 1; i <= m; i++)
scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);
sort(a+1, a+n+1, comp);
sort(b+1, b+m+1, comp);
for (int i = n; i >= 0; i--)
{
int at = i%2, pre = (i+1)%2;
for (int j = m; j >= 1; j--)
{
for (int c = 2*maxc-1; c >= 0; c--)
{
upd(dp[at][j][c], dp[pre][j][c]);
upd(dp[at][j][c], dp[at][j+1][c]);
if (c >= b[j].c)
upd(dp[at][j][c], 1ll*b[j].v + dp[at][j+1][c-b[j].c]);
if (i < n && c < maxc && a[i+1].f >= b[j].f)
upd(dp[at][j][c], dp[pre][j][c+a[i+1].c] - 1ll*a[i+1].v);
}
}
}
printf("%lld\n", max(0ll, dp[0][1][0]));
}
Compilation message (stderr)
# | 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... |