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 MAXN = 10000010;
int N, K, L, POSITIONS[MAXN];
long long int ans[MAXN], pos[MAXN];
long long int delivery(int n, int k, int l, int positions[])
{
int id1 = 0, id2 = 0;
for(int i = 0; i < n; i++) pos[i + 1] = positions[i];
for(int i = 1; i <= n; i++)
if(pos[i] > l / 2)
{ id1 = i - 1; id2 = i; break; }
for(int i = 1; i <= id1; i++)
ans[i] = 2 * pos[i] + ans[(i / k) * k];
for(int i = n; i > id1; i--)
ans[i] = 2 * (l - pos[i]) + ans[n + 1 - ((n - i + 1) / k) * k];
long long int ANS = ans[id1] + ans[id2];
id1 = (id1 / k) * k;
id2 = n + 1 - ((n - id2) / k) * k;
long long int ANS2 = ans[id1] + l + ans[id1 + k + 1];
long long int ANS3 = ans[id2] + l + ans[id2 - k - 1];
// printf("ans[%d](%lld) + %d + ans[%d](%lld)\n", id2, ans[id2], l, id2 - k - 1, ans[id2 - k - 1]);
// printf("ans = %lld ans2 = %lld ans3 = %lld\n", ANS, ANS2, ANS3);
return min(ANS, min(ANS2, ANS3));
}
/*
int main ()
{
scanf("%d %d %d", &N ,&K, &L);
for(int i = 0; i < N; i++) scanf("%d", &POSITIONS[i]);
printf("%lld\n",delivery(N, K, L, POSITIONS));
}
*/
/*
4 2 8
1 2 3 5
*/
# | 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... |