#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll delivery(int N, int K, int L, int p[]) {
int l=0, r=0, t=-1;
ll ans=0, ans2=0;
for(int i=0; i<N; i++) if(p[i]<=L/2) t=i;
for(int i=K-1; i<=t; i+=K) ans+=2*p[i];
for(int i=N-K; i>t; i-=K) ans+=2*(L-p[i]);
for(int i=t; i>=0; i-=K) ans2+=2*p[i];
for(int i=t+1; i<N; i+=K) ans2+=2*(L-p[i]);
l=(t+1)%K, r=(N-t-1)%K;
if(!l && !r);
if(!l) ans+=2*(L-p[t+1]);
else if(!r) ans+=2*p[t];
else {
ll ans2=min(L*((l+r+K-1)/K), 2*p[t]+2*(L-p[t+1]));
if(l+r>K) {
ans2=min(ans2, (ll)L+2*p[t-(K-r)]);
ans2=min(ans2, (ll)L+2*(L-p[t+1+(K-l)]));
for(int i=t-l+1; i<=t; i++) if(t+1+K-(t-i)<N) ans2=min(ans2, (ll)L+2*p[i]+2*(L-p[t+1+K-(t-i)]));
}
ans+=ans2;
}
return min(ans, ans2);
}
# | 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... |