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>
#define fi first
#define se second
#define lo long long
#define inf 1000000000
#define md 1000000007
#define li 10000005
#define mp make_pair
#define pb push_back
using namespace std;
int n,k,l,A[li],bas,t,B[li],son;
long long delivery(int N,int K,int L,int positions[]){
lo int cevap=0;
n=N,k=K,l=L;
for(int i=0;i<n;i++) A[i]=positions[i];
for(int i=0;i<n;i++){
if(A[i]!=0) B[++t]=A[i];
}
bas=1,son=t;
while(bas<=son){
//printf("debug->: : %d %d \n",bas,son);
int z1,z2;
if(bas+k-1>son) z1=B[son];
else z1=B[bas+k-1];
if(son-k+1<bas) z2=B[bas];
else z2=B[son-k+1];
//cout<<z1;
//exit(0);
lo int cst1=z1-B[bas]+min(z1,l-z1)+min(B[bas],l-B[bas]);
lo int cst2=B[son]-z2+min(z2,l-z2)+min(B[son],l-B[son]);
//cout<<"ok->> :: :: "<<z1<<" :: "<<B[bas]<<' '<<endl;
//exit(0);
if(cst1<=cst2){
bas=min(bas+k-1,n)+1;
cevap+=cst1;
}
else {son=max(bas-k+1,1)-1;cevap+=cst2;}
}
return cevap;
}
//~ int main(){
//~ scanf("%d %d %d",&n,&k,&l);
//~ for(int i=0;i<n;i++) scanf("%d",&A[i]);
//~ int ty=delivery(n,k,l,A);
//~ printf("%d\n",ty);
//~ return 0;
//}
# | 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... |