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 np[MAXN];
ll Nl;
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++){
np[i] = p[i];
}
Nl = L;
for(int i = 0; i < N; i++){
pref[i] = np[i];
if(i >= K) pref[i] += pref[i-K];
}
for(int i = N - 1; i >= 0; i--){
suf[i] = L-np[i];
if(N-i > K) {
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 = 0; i+1+K < N; i++ ){
ans = min(ans, L + 2*pref[i] + 2*pref[i+K+1]);
}
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... |