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;
long long delivery(int N, int K, int L, int p[]) {
long long pref[N + 1], suff[N + 2];
memset(pref, 0, sizeof(pref));
memset(suff, 0, sizeof(suff));
for(int i = 0; i < N; ++i) {
if(i % K == 0) {
// ambil dr posisi sebelumnya itu sum, dengan distance seKarang
pref[i + 1] = pref[i] + p[i];
}
else
pref[i + 1] = pref[i] + p[i] - p[i - 1];
}
for(int i = N - 1; i >= 0; --i) {
if(i % K == (N - 1) % K) {
suff[i + 1] = suff[i + 2] + L - p[i];
}
else {
suff[i + 1] = suff[i + 2] + p[i + 1] - p[i];
}
}
long long mn = 1e18;
for(int i = 0; i <= N; ++i) {
//cout << pref[i] << " " << suff[i + 1] << endl;
mn = min(mn, pref[i] + suff[i + 1]);
}
return 2 * mn;
}
# | 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... |