# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
16517 | ggoh | Boxes with souvenirs (IOI15_boxes) | C++98 | 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<cstdio>
#include<algorithm>
long long a,i,mini,left[10000006],right[10000006];
long long min(long long XX,long long YY){return XX>YY?YY:XX;}
long long delivery(long long N,long long K,long long L,long long positions[])
{
for(i=0;i<N;i++)
{
left[i]=positions[i]<=L/2?positions[i]*2:L;
if(i+1>K)
{
left[i]+=left[i-K];
}
}
for(i=N-1;i>=0;i--)
{
right[i]=(L-positions[i])<=L/2?(L-positions[i])*2:L;
if(N-i>K)
{
right[i]+=right[i+K];
}
}
mini=min(left[N-1],right[0]);
for(i=1;i<N-1;i++)
{
mini=min(mini,left[i]+right[i+1]);
}
return mini;
}