#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
// #define F first
// #define S second
#include "boxes.h"
ll delivery(int N, int K, int L, int p[]) {
vector<ll> dpL(N, INT_MAX), dpR(N, INT_MAX);
FOR(i, N) {
if (p[i] <= L / 2) {
if (i >= K) dpL[i] = min(dpL[i], dpL[i-K] + 2ll * p[i]);
else dpL[i] = min(dpL[i], 2ll * p[i]);
// cout << "L " << i << ' ' << dpL[i] << endl;
} else {
if (i + K <= N) dpR[N-i] = min(dpR[N-i], dpR[N-i-K] + 2ll * (L - p[i]));
else dpR[N-i] = min(dpR[N-i], 2ll * (L - p[i]));
// cout << "R " << i << ' ' << dpR[N-i] << ' ' << 2ll * (L - p[i]) << endl;
}
}
ll mxL = -1, mxR = -1;
FOR(i, N) {
if (dpL[i] != INT_MAX) mxL = max(mxL, dpL[i]);
if (dpR[i] != INT_MAX) mxR = max(mxR, dpR[i]);
}
return mxL + mxR;
}
// signed main() {
// cin.tie(0); ios::sync_with_stdio(false);
// }
# | 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... |