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 <bits/stdc++.h>
#define lp(i,a,b) for(int i = a ; i < b ; i++)
#define ll long long
#define ff first
#define ss second
const int MAXN = 1e7 + 5;
const int inf = 1e9 + 10 ;
using namespace std ;
//Declaracoes
int N , K , L ;
int pos[MAXN] ;
ll dp1[MAXN] , dp2[MAXN] ;
void print()
{
lp(i,0,N) cout<<dp1[i]<<" ";
cout<<endl ;
lp(i,0,N) cout<<dp2[i]<<" ";
cout<<endl;
}
//Funcao principal
ll delivery(int n , int k , int l , int positions[] )
{
//Globalizacao
N = n ; K = k ; L = l ;
lp(i,0,n) pos[i] = positions[i] ;
lp(i,0,n)
if( pos[i] == 0 ) pos[i] = inf , N-- ;
sort( pos , pos + n ) ;
n = N ;
lp(i,0,n)
{
dp1[i] = pos[i] * 2 ;
if( i - k >= 0 ) dp1[i] += dp1[i-k] ;
}
for( int i = n-1 ; i >= 0 ; i-- )
{
dp2[i] = ( L - pos[i]) * 2 ;
if( i + k < n ) dp2[i] += dp2[i+k] ;
}
ll best = 1LL * inf * MAXN ;
lp(i,0,n)
best = min( best , dp1[i] + dp2[i+1] ) ;
lp(i,0,n)
{
ll x = 0;
if( i + k < n ) x = dp2[i+k] ;
ll y = 0 ;
if( i-1 >= 0 ) y = dp1[i-1] ;
best = min( best , y + x + L ) ;
}
return best ;
}
# | 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... |