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>
using namespace std;
typedef long long ll ;
#include "boxes.h"
ll n , sz ;
ll num =0 ,ans = 0;
ll a[100009];
ll val[100009];
ll solve1(ll x){
return x ;
}
ll solve2 ( ll x ){
return sz - x ;
}
ll calc1(ll crnt , ll z ){
for(int i=0 ;i < n;i ++ ){
crnt-=val[i];
if(val[i])val[i] -= z;
if ( crnt == 0 ){
ll X = solve1(a[i]);
ll xxx = min (solve1(a[i]) , solve2(a[i]) );
return X + xxx;
}
}
return 0 ;
}
ll calc2(ll crnt , ll z ){
for(int i = n-1 ;i >=0 ; i-- ) {
crnt -= val[i];
if (val[i])val[i] -= z;
if ( crnt == 0 ){
ll X = solve2(a[i]);
ll xxx = min ( solve1(a[i]) , solve2(a[i]) );
return X + xxx;
}
}
return 0 ;
}
long long delivery(int N, int K, int L, int p[]) {
n = N , sz = L ;
num = n ;
for ( int i =0 ;i < n ;i ++ ){
a[i]=p[i];
val[i]=1;
}
while( num > 0 ){
ll val1=calc1( min ( num , (ll)K) , 0 ) ;
ll val2=calc2( min ( num , (ll)K) , 0 ) ;
if ( val1 <= val2 ) {
ans += val1;
calc1 ( min ( num , (ll)K) , 1 ) ;
}
else {
ans += val2;
calc2 ( min ( num , (ll)K) , 1 ) ;
}
num -= min ( num , (ll)K ) ;
}
return ans;
}
Compilation message (stderr)
boxes.cpp: In function 'll calc2(ll, ll)':
boxes.cpp:28:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
for(int i = n-1 ;i >=0 ; i-- ) {
~^~
# | 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... |