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;
typedef long long int lld;
int n, k, l;
vector<int> lhalf, rhalf;
int lsize, rsize;
long long delivery(int N, int K, int L, int p[]){
lld cost = 0;
n = N; k = K; l = L;
if(n==1) return min((lld)2*p[0], (lld)2*(l-p[0]));
/*
if(k==1){
lld ssss = 0;
for(int i=0;i<n;i++){
ssss += min((lld)2*p[i], (lld)2*(l-p[i]));
}
return ssss;
}
*/
for(int i=0;i<n&&2*p[i]<=l;i++){
lhalf.push_back(p[i]);
}
lsize = (int) lhalf.size();
for(int i=n-1;i>=0&&2*(l-p[i])<l;i--){
rhalf.push_back(l-p[i]);
}
rsize = (int) rhalf.size();
while(lsize!=0&&rsize!=0&&2*lhalf[lsize-1]+2*rhalf[rsize-1]>l){
int left_beg, right_end;
int new_lsize = -1, new_rsize = -1;
left_beg = max(0, lsize-k); right_end = rsize-(k-(lsize-left_beg));
int mx_span = -1;
while(left_beg<=lsize){
int pos_to_the_left, pos_to_the_right;
if(left_beg==0) pos_to_the_left = 0;
else pos_to_the_left = lhalf[left_beg-1];
if(right_end==0) pos_to_the_right = 0;
else pos_to_the_right = rhalf[right_end-1];
if(l-(pos_to_the_left+pos_to_the_right)>mx_span){
mx_span = l-(pos_to_the_left+pos_to_the_right);
new_lsize = left_beg;
new_rsize = right_end;
}
left_beg++; right_end--;
}
if(lsize==new_lsize){
cost += (lld) 2*rhalf[rsize-1];
}else if(rsize==new_rsize){
cost += (lld) 2*lhalf[lsize-1];
}else{
cost += (lld)l;
}
lsize = new_lsize;
rsize = new_rsize;
}
int pos_right = rsize-1;
int pos_left = lsize-1;
while(pos_right>=0){
cost += 2*rhalf[pos_right];
pos_right -= k;
}
while(pos_left>=0){
cost += 2*lhalf[pos_left];
pos_left -= k;
}
return cost;
}
# | 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... |