# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
979556 | kilkuwu | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 348 KiB |
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>
#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
long long delivery(int N, int K, int L, int p[]) {
int split = std::upper_bound(p, p + N, L / 2) - p;
int left = split;
int right = split;
long long ans = 0;
while (left >= K) {
ans += p[left - 1] * 2;
left -= K;
}
while (N - right >= K) {
ans += (L - p[right]) * 2;
right += K;
}
// now what can we do ?
// we can go in either direction
if (right == N && left == 0) return ans;
if (right == N || left == 0) {
if (right == N) {
return ans + p[left - 1] * 2;
} else {
return ans + (L - p[right]) * 2;
}
}
// both of em are non negative
long long naive = ans + p[left - 1] * 2 + (L - p[right]) * 2;
// that's the naieve solution
int tot = left + N - right;
long long round = ans + L;
if (tot > K) {
int left_remain = tot - K;
int right_remain = tot - K;
round += std::min(p[left_remain - 1], L - p[N - right_remain]) * 2;
}
ans += std::min(naive, round);
return ans;
}
#ifdef LOCAL
int main() {
int N, K, L, i;
std::cin >> N >> K >> L;
int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
for (i = 0; i < N; i++) {
std::cin >> p[i];
}
std::cout << delivery(N, K, L, p) << "\n";
return 0;
}
#endif
Compilation message (stderr)
# | 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... |