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;
const long long int INF = 1e18 + 7;
int N, K, L, POSITIONS[MAXN];
long long int clk[MAXN], cnt[MAXN], pos[MAXN];
long long int delivery(int n, int k, int l, int positions[])
{
for(int i = 0; i < n; i++) pos[i + 1] = positions[i];
for(int i = 1; i <= n; i++)
cnt[i] = 2 * pos[i] + cnt[(i / k) * k];
for(int i = n; i > 0; i--)
clk[i] = 2 * (l - pos[i]) + clk[n + 1 - ((n - i + 1) / k) * k];
long long int ans = INF;
for(int i = 1; i < n; i++)
ans = min(ans, cnt[i] + clk[i + 1]);
for(int i = 1; i + k + 1 <= n; i++)
ans = min(ans, cnt[i] + l + clk[i + k + 1]);
// 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 ans;
}
/*
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... |