# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102245 | Leonardo_Paes | Boxes with souvenirs (IOI15_boxes) | C++11 | 0 ms | 0 KiB |
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;
int n, k, l, vet[MAXN];
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;
}
int main(){
cin >> n >> k >> l;
for(int i=0; i<n; i++){
cin >> vet[i];
}
cout << delivery(n, k, l, vet) << endl;
}