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 ll long long
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
ll ans = 0 ;
int m = N,split=0;
for(int i = 0 ; i < N ;i++ )
if( p[i] > L/2 ){
m = i ;
if( i )
split = (p[i]-p[i-1])*2 > L ;
break ;
}
int l = -1 , r = N ;
for(int i = 0 ; i < m ; i++ ){
if( (i+1) % K == 0 ){
ans += p[i]*2 ;
l = i ;
}
}
for(int i = N-1 ; i >= m ; i-- ){
if( (N-i)%K==0 ){
ans += 2*(L-p[i]) ;
r = i ;
}
}
// cerr << ans << endl;
if( split ){
if( m-1 >= l + 1 ){
ans += p[m-1]*2 ;
}
if( m <= r-1 ){
ans += (L-p[m])*2;
}
}else {
if( l == m-1 ){
if( r != m )ans += (L-p[m])*2 ;
}
else if( r == m ){
if( l != m-1 )ans += (p[m-1])*2;
}
else ans += L ;
}
return ans;
}
// int main() {
// int N, K, L, i;
// cin >> N >> K >> L ;
// int p[N] ;
// for (i = 0; i < N; i++) {
// cin >> p[i] ;
// }
// cout << delivery(N,K,L,p);
// 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... |