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;
const int MAXN = 1e7 + 10;
ll pref[MAXN], suf[MAXN];
const ll INF = 1e18 + 10;
long long delivery(int N, int K, int L, int p[]) {
for(int i = 0; i < N; i++){
pref[i] = p[i];
if(!(i < K)) pref[i] += pref[i-K];
}
for(int i = N - 1; i >= 0; i--){
suf[i] = L-p[i];
if(!(K+i >= N)) {
suf[i] += suf[i+K];
}
}
// vai e volta por um lado
ll ans = min(2*suf[0], 2*pref[N-1]);
if(K >= N) ans = min(ans, (ll) L);
// achar volta
if(K < N){
for(int i = 1; i+K < N; i++ ){
ans = min(ans, L + 2*pref[i-1] + 2*suf[i+K]);
}
ans = min(ans, L + 2*pref[N-K-1]);
ans = min(ans, L + 2*suf[K]); // dou a volta, e pego o resto com uma ida do outro lado
}
return ans;
//return 0;
}
# | 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... |