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 delivery(int N_, int K_, int L_, int p[])
{
ll L = L_; ll N = N_; ll K = K_;
deque<ll> v(N);
for (int i = 0; i < N; i++)
v[i] = p[i];
sort(v.begin(), v.end());
ll res = 0;
while (v.size())
{
ll indexLeft = max((ll)v.size() - K, 0ll);
ll indexRight = min((ll)v.size() - 1, K - 1);
if (v[indexLeft] > L / 2)
{
res += (L - v[indexLeft]) * 2;
for (int i = 0; i < K && v.size(); i++)
v.pop_back();
}
else if (v[indexRight] <= L / 2)
{
res += v[indexLeft] * 2;
for (int i = 0; i < K && v.size(); i++)
v.pop_front();
}
else
{
res += L * ((v.size() + K - 1) / K);
break;
}
}
return res;
}
# | 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... |