# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
976775 | 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] == 0) continue;
if ( p[i] * 2 > L) {
ard.push_back(p[i]);
}
else {
if (p[i] * 2 < L) urd.push_back(p[i]);
else cnt ++;
}
}
ll Ard = 0, A = 0;
ll Urd = 0, U = 0;
ans = 0;
reverse(ard.begin(), ard.end());
for (i = urd.size() - 1; i >= 0; i -= K) U += urd[i];
j = i + K;
for (i = ard.size() - 1; i >= 0; i -= K) A += (L - ard[i]);
r = i + K;
for (i = K - 1; i < urd.size(); i += K) Urd += (urd[i]);
for (i = K - 1; i < ard.size(); i += K) Ard += ( L - ard[i]);
// cout << ans << endl;
cnt_urd = j + 1;
cnt_ard = r + 1;
U *= 2;
A *= 2;
Urd *= 2;
Ard*= 2;
// cout << cnt_urd << " " << cnt_ard << endl;
// cout << U << " " << A << endl;
// cout << Urd << " " << Ard << endl;
res = ((cnt_ard + cnt_urd + cnt + K - 1) / K) * L;
res = res + Urd + Ard;
// cout << res << endl;
if ( cnt_ard != 0) {
res = min(res, ((Urd + A+ ((cnt_urd + cnt + K - 1)/K) * L) ));
}
// cout << res << endl;
if ( cnt_urd != 0) {
res = min(res, (( U + Ard+ ((cnt_ard + cnt + K - 1)/K) * L) ));
}
// cout << res << endl;
if ( cnt_ard != 0 && cnt_urd != 0) {
res = min(res, ((A + U+ ((cnt + K - 1)/K) * L) ));
}
return res;
}