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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
ll delivery(int n,int k,int l,int p[])
{
sort(p,p+n);
ll res=(1ll<<60);
auto go=[&](int t)
{
ll now=0;
int x=0;
while(x<n&&p[x]==0) x++;
while(x<n)
{
int y=min(n-1,x+k-1);
if(p[y]<=l/2) now+=(2*p[y]);
else if(p[x]>l/2) now+=(2*(l-p[x]));
else if(t==0) now+=l;
else if(t==1)
{
int a=x;
while(p[a+1]<=l/2) a++;
now+=(2*p[a]);
x=a+1-k;
}
x+=k;
}
res=min(res,now);
};
go(0);
go(1);
for(int i=0;i<n;i++) p[i]=(l-p[i])%l;
sort(p,p+n);
go(0);
go(1);
return res;
}
# | 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... |