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 <stdio.h>
#include <stdlib.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define N 100100
ll n,k,m,ans,x,now1,now2,nn,a[N],b[N];
long long delivery(int NN, int K, int L, int ppp[]) {
nn=NN;
k=K;
for(ll i=1;i<=nn;++i){
x=ppp[i-1];
if(x<L-x)a[++n]=x;
else b[++m]=L-x;
}
sort(a+1,a+1+n);
sort(b+1,b+1+m);
now1=now2=0;
while(n-now1>=k){
now1=now1+k;
ans+=a[now1]*2;
}
while(m-now2>=k){
now2=now2+k;
ans+=b[now2]*2;
}
if(now1>=n&&now2>=m)return ans;
if(now1>=n)return ans+b[m]*2;
if(now2>=m)return ans+a[n]*2;
x=n-now1+m-now2;
if(x<=k){
ans+=min(a[n]*2+b[m]*2,1ll*L);
}
else{
ans+=min(min(1ll*L*2,a[n]*2+b[m]*2),min(a[now1+(x-k)]*2+m,b[now2+(x-k)]*2+m));
}
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... |