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 <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#ifdef DEBUG
#define debug(x) cout << #x << ' ' << x << '\n'
#else
#define debug(x)
#endif
long long delivery(int N, int K, int L, int p[]) {
int idx = 0;
int left = N;
long long ans = 0ll;
while (left > 0) {
vector<int> cur;
for (int i = idx; i < min(idx + K, N); i++) {
cur.push_back(p[i]);
left--;
}
idx += K;
long long takeLeft = 0ll;
long long takeRight = 0ll;
{
int pos = 0;
for (auto& x : cur) {
takeLeft += (long long) (x - pos);
debug(takeLeft);
pos = x;
}
takeLeft += (long long) (min(pos, L - pos));
}
{
int pos = L;
reverse(cur.begin(), cur.end());
for (auto& x : cur) {
takeRight += (long long) (pos - x);
debug(takeRight);
pos = x;
}
takeRight += (long long) (min(pos, L - pos));
}
ans += min(takeLeft, takeRight);
debug(ans);
}
return ans;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, l, p[1005];
cin >> n >> k >> l;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
cout << delivery(n, k, l, p) << endl;
return 0;
}
*/
# | 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... |