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;
long long delivery(int N, int K, int L, int p[]) {
ll ans=0;
int l=0,r=N-1,aux,in=0;
sort(p,p+N);
while (l<N && p[l]==0) l++;
for (;l<N;l+=K) {
aux = min(l+K-1,N-1);
if (p[aux]>L/2) break;
ans += min({L,2*p[aux],2*(L-p[l])});
}
for (;r>=l;r-=K) {
aux = max(r-K+1,l);
if (p[aux]<=L/2) break;
ans += min({L,2*p[r],2*(L-p[aux])});
}
if (l<=r) {
for (in=l;in<=r;in++) if (p[in]>L/2) break;
in--;
if (r-l+1 > K) ans += min(2*L,2*p[in] + 2*(L-p[in+1]));
else ans += min({L,2*p[r],2*(L-p[l])});
}
return ans;
}
# | 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... |