# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
717304 | tigar | 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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dpcw[10000010], dpccw[10000010], pos[10000010];
ll delivery(ll N, ll K, ll L, ll* positions)
{
sort(positions, positions+N);
for(int i=0; i<K; i++)dpccw[i]=min(L, 2*positions[i]);
for(int i=K; i<N; i++)dpccw[i]=dpccw[i-K]+min(L, 2*positions[i]);
for(int i=N-1; i>N-K; i--)dpcw[i]=min(N, (N-positions[i])*2);
for(int i=N-K; i>=0; i--)dpcw[i]=dpcw[i+K]+min(N, (N-positions[i])*2);
ll rezz=dpcw[0];
for(int i=0; i<N-1; i++)rezz=min(rezz, dpcw[i+1]+dpccw[i]);
rezz=min(rezz, dpccw[N-1]);
return rezz;
}
/*int main()
{
ll n, k, l;
cin>>n>>k>>l;
for(int i=0; i<n; i++)cin>>pos[i];
cout<<delivery(n, k, l, pos);
return 0;
}*/