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 <vector>
template<typename T> bool ckmax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool ckmin(T& a, const T& b) {return b<a?a=b,1:0;}
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
long long delivery(int N, int K, int L, int p[]) {
std::vector<ll> gl(N+1), gr(N+1);
for(int i=0;i<N;++i)
{
gl[i+1]=p[i]*2;
if(i>=K) gl[i+1]+=gl[i+1-K];
}
for(int i=0;i<N;++i)
{
gr[i+1]=(L-p[N-1-i])*2;
if(i>=K) gr[i+1]+=gr[i+1-K];
}
ll ans=INF;
// no cross:
for(int i=0;i<=N;++i)
ckmin(ans, gl[i]+gr[N-i]);
//cross:
if(K>=N) ckmin(ans, (ll)L);
else
for(int i=0;i<=N-K;++i)
ckmin(ans, gl[i]+gr[N-K-i]+L);
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... |