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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
#define pb emplace_back
ll delivery(int N, int K, int L, int p[]) {
ll pref[N + 1] = {};
ll suff[N + 1] = {};
for(int i = 1; i <= N; ++i) {
if((i - 1) % K == 0) {
// have to start a new trip
pref[i] = 2 * p[i - 1];
} else {
// can continue the last trip
pref[i] = 2 * (p[i - 1] - p[i - 2]) + pref[i - 1];
}
}
suff[0] = 0;
for(int i = 1; i <= N; ++i) {
if((i - 1) % K == 0) {
// have to start a new trip
suff[i] = 2 * (L - p[N - i]);
} else {
// can continue the last trip
suff[i] = 2 * (p[N - (i - 1)] - p[N - i]) + suff[i - 1];
}
}
ll ans = LLONG_MAX;
for(int i = 0; i <= N; ++i) {
ans = min(ans, pref[i] + suff[N - i]);
if(N - i - K >= 0)
ans = min(ans, pref[i] + suff[N - i - K] + L);
}
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... |