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 delivery(int N, int K, int L, int p[]) {
sort(p,p+N);
long long arr[N],brr[N],cursum=0;
int cnt=0;
for(int i=0;i<N;i++){
if(p[i]==0){
arr[i]=0;
continue;
}
arr[i]=cursum+min(p[i]*2,L);
cnt++;
if(cnt==K){
cursum+=min(p[i]*2,L);
cnt=0;
}
}
cursum=0;
cnt=0;
for(int i=N-1;i>=0;i--){
if(p[i]==0){
arr[i]=((i==N-1)?(0):(brr[i+1]));
continue;
}
brr[i]=cursum+min((L-p[i])*2,L);
cnt++;
if(cnt==K){
cursum+=min((L-p[i])*2,L);
cnt=0;
}
}
long long ans=min(brr[0],arr[N-1]);
//cout << brr[0] << '\n';
for(int i=0;i<N-1;i++){
//cout << arr[i] << ' ' << brr[i+1] << '\n';
ans=min(ans,arr[i]+brr[i+1]);
}
//cout << arr[N-1] << '\n';
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... |