# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
780211 | vjudge1 | Boxes with souvenirs (IOI15_boxes) | C++17 | 53 ms | 4200 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>
using namespace std;
#define pb push_back
#define pii pair<long long, long long>
#define st first
#define nd second
#define sp " "
#define endl "\n"
#define ll long long
long long delivery(int N, int K, int L, int p[]) {
int n = N, k = K, l = L;
sort(p, p + n);
ll curr = 0;
for (int i = 0; i < n; i += k){
int to = min(n - 1, i + k - 1);
if (p[to] <= L / 2){
curr += 2 * p[to];
}
else if (p[i] >= L / 2){
curr += 2 * (L - p[i]);
}
else curr += L;
}
ll ans = curr;
curr = 0;
int pos = 0;
while(pos < n && p[pos] <= L / 2) pos++;
for (int i = pos - 1; i >= 0; i -= k){
int to = max(0, i - k + 1);
curr += 2 * min(p[i], L / 2);
}
for (int i = pos; i < n; i += k){
int to = min(n - 1, i + k - 1);
curr += 2 * (L - p[i]);
}
ans = min(ans, curr);
curr = 0;
pos = 0;
while(pos < n && p[pos] < (L + 1) / 2) pos++;
for (int i = pos - 1; i >= 0; i -= k){
int to = max(0, i - k + 1);
curr += 2 * min(p[i], L / 2);
}
for (int i = pos; i < n; i += k){
int to = min(n - 1, i + k - 1);
curr += 2 * (L - p[i]);
}
ans = min(ans, curr);
curr = 0;
reverse(p, p + n);
for (int i = 0; i < n; i += k){
int to = min(n - 1, i + k - 1);
if (p[i] <= L / 2){
curr += 2 * p[i];
}
else if (p[to] >= L / 2){
curr += 2 * (L - p[to]);
}
else curr += L;
}
return min(ans, curr);
}
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... |