This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, m, dp[2][2069][52][52], mn, res; //{komp sekarang, order sekarang, core tersisa komp, needed core order}
struct machine
{
long long c, f, v;
bool operator<(const machine other) const
{
return f<other.f;
}
} a[2069], b[2069];
int main()
{
long long i, j, ci, cj, ii, jj, cci, ccj;
scanf("%lld", &n);
for (i=1; i<=n; i++)
{
scanf("%lld%lld%lld", &a[i].c, &a[i].f, &a[i].v);
}
scanf("%lld", &m);
for (i=1; i<=m; i++)
{
scanf("%lld%lld%lld", &b[i].c, &b[i].f, &b[i].v);
}
sort(a+1, a+n+1);
sort(b+1, b+m+1);
for (i=n; i>=1; i--)
{
for (j=m; j>=1; j--)
{
// printf("i = %lld = j = %lld\n", i, j);
for (ci=1; ci<=a[i].c; ci++)
{
for (cj=1; cj<=b[j].c; cj++)
{
// printf("ci = %lld cj = %lld\n", ci, cj);
dp[i%2][j][ci][cj] = 0;
if (cj == b[j].c) dp[i%2][j][ci][cj] = dp[i%2][(j+1)][ci][b[j+1].c]; //boleh skip order kalau belum pernah assign core ke order ini
dp[i%2][j][ci][cj] = max(dp[i%2][j][ci][cj], dp[(i+1)%2][j][a[i+1].c][cj]);
// if (cj == 0) dp[i%2][j%2][ci][cj] += b[j].v; //berarti order j fullfiled
mn = min(ci, cj);
//Sumbangin core komputer i ke core order j
ii = i%2;
jj = j;
ccj = cj-mn;
cci = ci-mn;
res = 0;
if (ccj == 0)
{
jj = (j+1);
res += b[j].v;
ccj = b[j+1].c;
// printf("masuk tolol\n");
}
if (cci == 0)
{
ii = (i+1)%2;
cci = a[i+1].c;
}
if (ci == a[i].c)
{
res -= a[i].v;
}
if (a[i].f>=b[j].f) dp[i%2][j][ci][cj] = max(dp[i%2][j][ci][cj], res+dp[ii][jj][cci][ccj]);
// printf("dp[%lld][%lld][%lld][%lld] = %lld res = %lld\n", i, j, ci, cj, dp[i%2][j][ci][cj], res);
}
}
}
}
printf("%lld\n", dp[1][1][a[1].c][b[1].c]);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
clo.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%lld%lld%lld", &a[i].c, &a[i].f, &a[i].v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%lld", &m);
| ~~~~~^~~~~~~~~~~~
clo.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%lld%lld%lld", &b[i].c, &b[i].f, &b[i].v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |