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>
#include <set>
long long delivery(int numTeams, int capacity, int numSections, int p[])
{
std::sort(p, p + numTeams);
auto DistTo0 = [&] (int x)
{
return std::min(x, numSections - x);
};
int done = 0;
long long sec = 0;
while (done < numTeams)
{
int boxes = capacity;
//std::cout << "MO " << DistTo0(pos) << std::endl;
sec += DistTo0(p[done]);
while (true)
{
int oldPos = p[done];
int numToGive = 0;
while (numToGive < boxes && p[done + numToGive] == oldPos)
numToGive++;
done += numToGive;
boxes -= numToGive;
if (boxes <= 0 || done >= numTeams)
{
//std::cout << "MB " << std::abs(p[done] - oldPos) << std::endl;
sec += DistTo0(oldPos);
break;
}
//std::cout << "MS " << std::abs(p[done] - oldPos) << std::endl;
sec += std::abs(p[done] - oldPos);
}
}
return sec;
}
# | 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... |