#include <bits/stdc++.h>
#include "boxes.h"
// #include "grader.cpp"
using namespace std;
// #define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define ar array
#define nl '\n'
template <typename A, typename B>
bool chmin(A &a, const B &b) {
if(a > b) {
return a = b, true;
}
return false;
}
template <typename A, typename B>
bool chmax(A &a, const B &b) {
if(a < b) {
return a = b, true;
}
return false;
}
long long delivery(int n, int k, int l, int p[]) {
vector<long long> pref(n + 1), suf(n + 1);
for(int i = 0; i < n; i++) {
pref[i + 1] = pref[ max(0, i - k + 1) ] + 2 * p[i];
}
for(int i = n - 1; i >= 0; i--) {
suf[i] = suf[ min(n, i + k) ] + 2 * (l - p[i]);
}
long long ans = pref[n];
for(int i = 0; i + k <= n; i++) {
chmin(ans, pref[i] + suf[i + k] + l);
}
for(int i = 0; i < n; i++) {
chmin(ans, pref[i] + suf[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... |