# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
976745 | Amaarsaa | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 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<bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long ;
ll delivery(ll N, ll K, ll L, ll p[]) {
ll ans, cnt_ard, cnt_urd, res;
vector < ll > ard, urd;
ll cnt = 0, i, j, r, s;
for (i = 0; i < N; i ++) {
if ( p[i] * 2 > L) {
ard.push_back(p[i]);
}
else {
if (p[i] * 2 < L) urd.push_back(p[i]);
else cnt ++;
}
}
ans = 0;
for (i = K - 1; i < urd.size(); i += K) {
ans += urd[i];
}
j = i - K + 1;
reverse(ard.begin(), ard.end());
for (i = K - 1; i < ard.size(); i += K) {
ans += (L - ard[i]);
}
r = i - K + 1;
ans *= 2;
cnt_urd = urd.size() - j;
cnt_ard = ard.size() - r;
res = ((cnt_ard + cnt_urd + cnt + K - 1) / K) * L;
if ( cnt_ard != 0) {
res = min(res, (((L - ard.back()) * 2) + ((cnt_urd + cnt + K - 1)/K) * L) );
}
if ( cnt_urd != 0) {
res = min(res, (((urd.back()) * 2) + ((cnt_ard + cnt + K - 1)/K) * L) );
}
if ( cnt_ard != 0 && cnt_urd != 0) {
res = min(res, (((L - ard.back()) * 2) + (urd.back() * 2)+ ((cnt + K - 1)/K) * L) );
}
return res + ans;
}