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 "boxes.h"
#include <bits/stdc++.h>
#define M 10000010
#define inf 0x3f3f3f3f3f3f3f
using namespace std;
long long mi[M],dpl[M],dpr[M];
long long delivery(int N, int K, int L, int p[])
{
if(K==1)
{
long long ans=0;
for(int i=0;i<N;i++) ans+=min(abs(L-p[i]),abs(p[i]))*2;
return ans;
}
if(K==N)
{
int li=p[0],lx=p[0],ri=p[N-1],rx=p[N-1];
for (int i=0;i<N;i++)
{
if(p[i]*2<L) lx=p[i];
if(p[i]*2==L) return L;
if(p[i]*2>L)
{
ri=p[i];
break;
}
}
if(li*2>L) return (L-li)*2;//*
else
if(rx*2<L)return rx*2;//*
else
if (L<lx*2+(L-ri)*2) return L;
else return lx*2+(L-ri)*2;//*
}
dpl[0]=0;
for(int i=1;i<=N;i++) dpl[i]=dpl[max(i-K,0)]+p[i-1]*2;
dpr[N+1]=0;
for(int i=N;i>=1;i--) dpr[i]=dpr[min(N+1,i+K)]+(L-p[i-1])*2;
long long ans=inf;
for(int i=1;i<=N+1;i++) ans=min(ans,dpl[i-1]+dpr[i]);
for(int i=0;i<N;i++)
{
if(i+K<=N)
{
ans=min(ans,L+dpl[i]+dpr[i+K+1]);
}
}
return ans;
}
# | 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... |