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);
vector<ll> presu(K,0), sufsu(K,0);
pre[0] = 0;
suf[N] = 0;
for(int i = 0; i < N; ++i){
pre[i+1] = p[i] + presu[i%K];
presu[i%K]+=2*p[i];
}
for(int i = N; i; --i){
suf[i-1] = L-p[i-1] + sufsu[(N-i)%K];
sufsu[(N-i)%K] += 2*(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... |