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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1000000000000000000LL;
long long delivery(int n, int k, int l, int p[]) {
vector<ll> dp1(n + 1, M);
dp1[0] = 0;
for (int i = 0; i < n; i++)
{
dp1[i + 1] = dp1[max(0, i + 1 - k)] * 2 * p[i];
}
vector<ll> dp2(n + 1, M);
dp2[0] = 0;
for (int i = 0, j = n - 1; i < n; i++, j--)
{
dp2[i + 1] = dp2[max(0, i + 1 - k)] + 2 * (l - p[j]);
}
ll res = M;
int atLeast = n / k;
if (n % k != 0) atLeast++;
res = min(res, (ll) atLeast * l);
for (int i = 0; i <= 1; i++)
{
int a = 0;
int b = n;
ll cur = M;
while (b - a > 1)
{
int mid = ( a + b) / 2;
ll val1 = dp1[i] + (ll)mid * l * k + dp2[max<ll>(0, n - i- (ll)mid * k)];
ll val2 = dp1[i] + (ll)mid * l * (k + 1) + dp2[max<ll>(0, n - i- (ll)mid * (k + 1))];
res = min(val1, res);
res = min(val2, res);
if (val1 < val2)
{
b = mid;
} else
{
a = mid;
}
}
}
return res;
}
/*
5 5 100
1 3 6 53 78
*/
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:37:12: warning: unused variable 'cur' [-Wunused-variable]
37 | ll cur = M;
| ^~~
# | 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... |