#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const ll LLINF = 1e18;
long long delivery(int n, int k, int l, int p[]) {
vl a(n);
for (int i = 0; i < n; i++) a[i] = p[i];
a.push_back(l);
vl tr(n+1);
ll tot = 0;
for (int i = n-1; i >= 0; i--) {
tot += a[i+1]-a[i];
tr[i] = tot + min(a[i], a[n]-a[i]);
if ((n-i)%k==0) tot += min(a[i], a[n]-a[i]) + a[n]-a[i];
}
tot = 0;
ll ans = tr[0];
for (int i = 0; i < n; i++) {
tot += a[i] - (i ? a[i-1] : 0);
ll tl = tot + min(a[i], a[n]-a[i]);
ans = min(ans, tl+tr[i+1]);
if ((i+1)%k==0) tot += min(a[i], a[n]-a[i]) + a[i];
}
//cout << ans << endl;
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... |