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 pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
#define MAXN 10000005
using namespace std;
ll art[MAXN];
ll azl[MAXN];
long long delivery(int N, int K, int L, int p[]) {
int kn=K;
ll tm=0;
ll ans=1e18;
for(int i=0;i<N;i++){
if(i==0)tm+=p[i];
else tm+=p[i]-p[i-1];
art[i]=tm+p[i];
if(--kn==0){
tm+=2*p[i];
kn=K;
}
if(i==N-1)ans=min(ans,art[i]);
//printf("i=%d p=%d kn=%d art=%lld\n",i,p[i],kn,art[i]);
}
kn=K;tm=0;
for(int i=N-1;i>=0;i--){
if(i==N-1)tm+=(L-p[i]);
else tm+=p[i+1]-p[i];
azl[i]=tm+(L-p[i]);
if(--kn==0){
tm+=2*(L-p[i]);
kn=K;
}
if(i==0)ans=min(ans,azl[i]);
//printf("i=%d p=%d kn=%d azl=%lld\n",i,p[i],kn,azl[i]);
}
for(int i=0;i<N;i++){
if(ans>art[i]+azl[i+1]){
//printf("1: i=%d\n",i);
ans=art[i]+azl[i+1];
}
}
for(int i=0;i<N;i++){
if(i+K+1<=N && ans>art[i]+L+azl[i+K+1]){
//printf("2: i=%d\n",i);
ans=art[i]+L+azl[i+K+1];
}
}
umin(ans,art[N-1-K]+L);
umin(ans,azl[K]+L);
//cout<<ans<<endl;
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... |