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>
using namespace std;
long long pre[10000001],suf[10000001],p[10000001];
long long delivery(int n, int k, int l, int o[]){
for(int i=0;i<n;i++){
p[i+1]=o[i];
}
sort(p+1,p+n+1);
for(int i=1;i<=k;i++){
pre[i]=2*p[i];
}
pre[0]=0,suf[n+1]=0;
for(int i=k+1;i<=n;i++){
pre[i]=pre[i-k]+2*p[i];
}
for(int i=1;i<=k;i++){
suf[n+1-i]=2*(l-p[n+1-i]);
}
for(int i=k+1;i<=n;i++){
suf[n+1-i]=suf[n+1-i+k]+2*(l-p[n+1-i]);
}
long long ans=1e18;
for(int i=0;i<=n;i++){
ans=min(ans,pre[i]+suf[i+1]);
}
for(int i=0;i<=n-k;i++){
ans=min(ans,pre[i]+suf[i+k+1]+l);
}
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... |