#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, k=0, t1=-1, t2=N;
ll ans=0, ans2=LLONG_MAX;
for(int i=0; i<N; i++) if(p[i]<=(L-1)/2) t1=i;
for(int i=0; i<N; i++) if(p[i]>L/2) {t2=i; break;}
for(int i=K-1; i<=t1; i+=K) ans+=2*p[i];
for(int i=N-K; i>=t2; i-=K) ans+=2*(L-p[i]);
l=(t1+1)%K, r=(N-t2)%K, k=t2-t1-1;
ans+=(ll)((k+K-1)/K)*L;
int tmp=K-(k+K-1)%K-1;
if(tmp>=l+r) return ans;
if(tmp>=r) ans2=min(ans2, 2ll*p[t1-(tmp-r)]);
if(tmp>=l) ans2=min(ans2, 2ll*(L-p[t2+(tmp-l)]));
for(int i=t1-l+1; i<=t1; i++) if(tmp>=(t1-i) && tmp-(t1-i)<r) ans2=min(ans2, 2ll*p[i]+2*(L-p[t2+tmp-(t1-i)]));
ans2=min(ans2, (ll)((l+r-tmp+K-1)/K)*L);
return 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... |