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 <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <iostream>
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector<long long> left_positions;
vector<long long> right_positions;
long long no_round_trips = 0;
for (int i = 0; i < N; i++){
if (p[i] <= L/2){
left_positions.push_back(p[i]);
}
}
for (int i = N - 1; i >= 0; i--){
if (p[i] > L/2){
right_positions.push_back(L - p[i]);
}
}
int current_boxes = 0;
while (left_positions.size() > 0){
no_round_trips += left_positions[left_positions.size() - 1] * 2;
current_boxes = K;
for (;left_positions.size() && current_boxes > 0; current_boxes--){
left_positions.pop_back();
}
}
while (right_positions.size() > 0){
no_round_trips += right_positions[right_positions.size() - 1] * 2;
current_boxes = K;
for (; right_positions.size() && current_boxes > 0; current_boxes--){
right_positions.pop_back();
}
}
long long one_round_trip = L;
for (int i = 0; i < N; i++){
if (p[i] <= L/2){
left_positions.push_back(p[i]);
}
}
for (int i = N - 1; i >= 0; i--){
if (p[i] > L/2){
right_positions.push_back(L - p[i]);
}
}
current_boxes = K;
while(current_boxes > 0){
if (right_positions.size() && left_positions.size() && left_positions[left_positions.size() - 1] > right_positions[right_positions.size() - 1]){
left_positions.pop_back();
} else {
if (right_positions.size() == 0 && left_positions.size()){
left_positions.pop_back();
}
if (right_positions.size()){
right_positions.pop_back();
}
}
current_boxes--;
}
current_boxes = 0;
while (left_positions.size() > 0){
one_round_trip += left_positions[left_positions.size() - 1] * 2;
current_boxes = K;
for (;left_positions.size() && current_boxes > 0; current_boxes--){
left_positions.pop_back();
}
}
while (right_positions.size() > 0){
one_round_trip += right_positions[right_positions.size() - 1] * 2;
current_boxes = K;
for (; right_positions.size() && current_boxes > 0; current_boxes--){
right_positions.pop_back();
}
}
//cout << min(one_round_trip, no_round_trips) << endl;
//cout << no_round_trips << endl;
return min(one_round_trip, no_round_trips);
return 0;
}
# | 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... |