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;
int dpcw[10000010], dpccw[10000010], pos[10000010];
ll delivery(int N, int K, int L, int* 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(L, (L-positions[i])*2);
for(int i=N-K-1; i>=0; i--)dpcw[i]=dpcw[i+K]+min(L, (L-positions[i])*2);
int rezz=dpcw[0];
/*for(int i=0; i<N; i++)cout<<dpcw[i]<<" ";
cout<<"\n";
for(int i=0; i<N; i++)cout<<dpccw[i]<<" ";*/
for(int i=0; i<N-1; i++)rezz=min(rezz, dpccw[i]+dpcw[i+1]);
rezz=min(rezz, dpccw[N-1]);
return rezz;
}
/*int main()
{
int 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;
}
/*3 2 8
1 2 5*/
Compilation message (stderr)
boxes.cpp:33:1: warning: "/*" within comment [-Wcomment]
33 | /*3 2 8
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |