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>
using namespace std;
long long delivery(int n,int k,int L,int pos[])
{
vector<long long>l(n+1),r(n+1);
sort(pos,pos+n);
int cntl=0;
for(int i=0;i<n;i++)
{
cntl++;
if(cntl>=k) l[cntl]=l[cntl-k]+2ll*pos[i];
else l[cntl]=2ll*pos[i];
}
int cntr=0;
for(int i=n-1;i>=0;i--)
{
cntr++;
if(cntr>=k) r[cntr]=r[cntr-k]+2ll*(L-pos[i]);
else r[cntr]=2ll*(L-pos[i]);
}
long long res=1e18;
for(int i=0;i<=n;i++)
{
res=min(res,l[i]+r[n-i]);
if(n-i-k>=0) res=min(res,l[i]+r[n-i-k]+L);
}
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... |