# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731953 | lucri | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 340 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 "boxes.h"
#include <bits/stdc++.h>
long long st[10000010],dr[10000010];
long long delivery(int N, int K, int L, int p[])
{
long long n=N,k=K,l=L;
std::sort(p,p+n);
st[0]=p[0]*2;
for(int i=1;i<n;++i)
{
if(i%k!=0)
st[i]=st[i-1]+2*(p[i]-p[i-1]);
else
st[i]=st[i-1]+2*p[i];
}
dr[n-1]=(l-p[n-1])*2;
for(int i=n-2;i>=0;--i)
{
if((i-(n-1))%k!=0)
dr[i]=dr[i+1]+2*(p[i+1]-p[i]);
else
dr[i]=dr[i+1]+2*(l-p[i]);
}
long long ans=std::min(dr[0],st[n-1]);
for(int i=0;i<n-1;++i)
ans=std::min(ans,st[i]+dr[i+1]);
if(k>=n)
ans=std::min(ans,l);
else
{
ans=std::min(ans,st[n-k-1]+l);
ans=std::min(ans,l+st[n-k]);
for(int i=0;i+k<n-1;++i)
ans=std::min(ans,st[i]+l+dr[i+k+1]);
}
return ans;
}
Compilation message (stderr)
# | 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... |