| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1359938 | NAMIN | Boxes with souvenirs (IOI15_boxes) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "boxes.h"
#define ll long long
using namespace std;
ll delivery(int N, int K, ll L, int p[]) {
ll ans = 0;
deque<ll> dq;
for(int i=0;i<N;i++)
dq.push_back(p[i]);
sort(dq.begin(),dq.end());
while(dq.size()>=K){
ll costl = min(L,dq[K-1]*2LL);
ll costr = min(L,(L-dq[N-K])*2LL);
if(costl<=costr){
ans += costl;
for(int i=0;i<K;i++)
dq.pop_front();
}
else{
ans += costr;
for(int i=0;i<K;i++)
dq.pop_back();
}
//cout << ans << ' ' << costl << ' ' << costr << endl;
}
if(dq.size()>0)
ans += min(min(L,dq.back()*2LL),min(L,(L-dq[0])*2LL));
return ans;
}
