# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79390 | Plurm | Boxes with souvenirs (IOI15_boxes) | C++11 | 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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector<int> a,b;
for(int i = 0; i < N; i++){
if(p[i] < L-p[i]){
a.push_back(p[i]);
}else{
b.push_back(L-p[i]);
}
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
vector<long long> dpa,dpb;
dpa.resize(a.size());
if(!a.empty())
dpa[0] = 2ll*a[0];
long long mn = (long long)(N+K-1)/(long long)K*(long long)L;
for(int i = 1; i < a.size(); i++){
mn = min(mn,dpa[i-1] + (long long)(N-i+K-1)/(long long)K*(long long)L);
dpa[i] = i >= K ? dpa[i-K] : 0ll;
dpa[i] += 2ll*(long long)a[i];
}
dpb.resize(b.size());
if(!b.empty())
dpb[0] = 2ll*b[0];
for(int i = 1; i < b.size(); i++){
mn = min(mn,dpb[i-1] + (long long)(N-i+K-1)/(long long)K*(long long)L);
for(int j = 0; j < a.size(); j++){
mn = min(mn,dpa[j] + dpb[i-1] + (long long)(N-i-j+K-2)/(long long)K*(long long)L);
}
dpb[i] = i >= K ? dpb[i-K] : 0ll;
dpb[i] += 2ll*(long long)b[i];
}
if(!b.empty()){
mn = min(mn,dpb[b.size()-1] + (long long)(N-b.size()-j+K-2)/(long long)K*(long long)L);
}
for(int j = 0; j < a.size(); j++){
mn = min(mn,dpa[j] + dpb[b.size()-1] + (long long)(N-b.size()-j+K-2)/(long long)K*(long long)L);
}
return mn;
}