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 <iostream>
#include <assert.h>
#include <utility>
#include <algorithm>
using namespace std;
long long delivery(int N, int K, int L, int p[])
{
long long res = 0, res2 = 0; int i, j, Lsz = 0, Rsz = 0;
for (i = 0; i < N && p[i] <= L / 2; i++);
for (i--; i >= 0 && p[i]; i--)
{
Lsz++;
if (Lsz == K) {res += 2 * p[i + K - 1]; Lsz = 0;}
}
for (j = N - 1; j >= 0 && p[j] > L / 2; j--);
for (j++; j < N; j++)
{
Rsz++;
if (Rsz == K) {res += 2 * (L - p[j - K + 1]); Rsz = 0;}
}
long long temp = 0;
if (Lsz) {temp += 2 * p[i + Lsz];}
if (Rsz) {temp += 2 * (L - p[j - Rsz]);}
res += min(temp, (long long)(Lsz + Rsz + K - 1) / K * L);
Lsz = Rsz = 0;
for (i = 0; i < N && p[i] == 0; i++);
for (; i < N && p[i] <= L / 2; i++)
{
Lsz++;
if (Lsz == K) {res2 += 2 * p[i]; Lsz = 0;}
}
for (j = N - 1; j >= 0 && p[j] > L / 2; j--)
{
Rsz++;
if (Rsz == K) {res2 += 2 * (L - p[j]); Rsz = 0;}
}
temp = 0;
if (Lsz) {temp += 2 * p[i - 1];}
if (Rsz) {temp += 2 * (L - p[j + 1]);}
res2 += min(temp, (long long)(Lsz + Rsz + K - 1) / K * L);
//cout << res << " " << res2 << " " << temp << " " << Lsz << " " << Rsz << "\n";
return min(res, res2);
}
# | 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... |