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;
typedef long long ll;
ll delivery(int N, int K, int L, int p[]) {
vector<ll> pre(N+1), suf(N+1);
pre[0] = 0;
suf[N] = 0;
for(int i = 0; i < N; ++i){
pre[i+1] = pre[i]+(i%K ? p[i]-p[i-1] : min(p[i],L-p[i]) + (i ? min(p[i-1],L-p[i-1]) : 0ll));
}
for(int i = N; i; --i){
suf[i-1] = suf[i]+((N-i)%K ? p[i]-p[i-1] : (i == N ? 0ll : min(p[i],L-p[i])) + min(p[i-1],L-p[i-1]));
}
ll ans = (1ll<<60);
for(int i = 0; i <= N; ++i){
ans = min(ans,pre[i]+suf[i]+(i ? min(p[i-1],L-p[i-1]) : 0) + (i == N ? 0 : min(p[i],L-p[i])));
}
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... |