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 ;
const int N = 1e7 + 4 ;
template <class T>
bool chmax( T& x , const T& y ){
bool f = 0 ;
if ( x < y ) x = y , f = 1 ;
return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
bool f = 0 ;
if ( x > y ) x = y , f = 1 ;
return f ;
}
int dpl[N] , dpr[N] ;
long long delivery(int n, int k, int l, int a[]) {
for ( int i = 0 ; i < n ; i ++ )
dpl[i] = ( i >= k ) ? dpl[i-k] + min(l,2*a[i]) : min(l,2*a[i]) ;
for ( int i = n-1 ; i >= 0 ; i -- )
dpr[i] = ( i+k < n ) ? dpr[i+k] + min(l,2*(l-a[i])) : min(l,2*(l-a[i])) ;
int ans = min ( dpl[n-1] , dpr[0] ) ;
for ( int i = 1 ; i < n ; i ++ ) chmin ( ans , dpl[i-1]+dpr[i] ) ;
return ans ;
}
/*
int a[N] ;
signed main(){
int n , k , l ; cin >> n >> k >> l ;
for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] ;
cout << delivery( n , k , l , a ) ;
}
//*/
# | 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... |