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>
using namespace std;
const int MAXN = 3e7 + 10;
typedef long long ll;
ll pre[MAXN], suf[MAXN];
ll delivery(int N, int K, int L, int positions[]){
ll sum;
for(int i=0; i<N; i++){
pre[i] = 2ll*positions[i];
if(i >= K)pre[i] += pre[i-K];
}
for(int i=N-1; i>=0; i--){
suf[i] = 2ll*(L-positions[i]);
if(i+K < N)suf[i] += suf[i+K];
}
sum = min(suf[0], pre[N-1]);
if(N==K)sum=min(sum, (ll)L);
for(int i=0; i<N-1; i++){
sum = min(sum, pre[i] + suf[i+1]);
if(i+K+1<N)sum = min(sum, pre[i] + L + suf[i+1+K]);
else sum = min(sum, pre[i] + L);
}
return sum;
}
# | 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... |