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>
#include "boxes.h"
using namespace std;
const int N = 1e7 + 2;
int n , k , len , bord;
long long L[N] , R[N];
long long delivery(int nn, int kk, int ll, int p[]) {
n = nn;
k = kk;
len = ll;
bord = -1;
long long ans = 1e18;
for(int i = 0 ; i < n ; i++)
{
L[i] = 2 * p[i];
if(i >= k)
L[i] += L[i - k];
if(2 * p[i] >= len && bord == -1)
bord = i;
ans = min(ans , L[i] + 1LL * len * ((n - i + k) / k));
}
for(int i = n - 1 ; i >= 0 ; i--)
{
R[i] = 2 * (len - p[i]);
if(i + k < n)
R[i] += R[i + k];
ans = min(ans , R[i] + 1LL * len * ((i + k - 1) / k));
}
for(int l = 0 ; l < bord ; l++)
{
long long res = 0;
res += L[l];
int tmp = (bord - l - 1 + k - 1) / k;
res += 1LL * tmp * len;
if(l + tmp * k + 1 < n)
res += R[l + tmp * k + 1];
ans = min(ans , res);
}
return ans;
}
# | 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... |