This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// M
#include<bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
const int N = 10000007;
int n, k, L, A[N];
ll P[N], S[N];
long long delivery(int _n, int _k, int _L, int _p[])
{
k = _k; L = _L;
for (int i = 0; i < _n; i ++)
if (_p[i])
A[++ n] = _p[i];
ll Mn = (n + k - 1) / k * (ll)L;
for (int i = 1; i <= n; i ++)
{
P[i] = P[i - 1];
if (i % k == 0)
P[i] += A[i];
}
for (int i = n; i; i --)
{
S[i] = S[i + 1];
if ((n - i + 1) % k == 0)
S[i] += L - A[i];
}
for (int i = 0; i <= n; i ++)
{
ll p = 0, s = 0;
if (i) p = P[i - 1] + A[i];
if (i < n) s = S[i + 2] + L - A[i + 1];
Mn = min(Mn, (p + s) * 2LL);
ll s2 = 0;
if (i + k + 1 <= n)
s2 = S[i + k + 2] + L - A[i + k + 1];
Mn = min(Mn, (p + s2) * 2LL + L);
}
return Mn;
}
# | 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... |