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>
#define ll long long
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
multiset<int>left,right;
for(int i=0;i<N;i++){
left.insert(p[i]);
right.insert(L-p[i]);
}
ll ans=0;
while(!left.empty()){
int k=K;
ll sl=0,sr=0;
vector<int>l,r;
while(!left.empty() && k--){
l.push_back(*left.begin());
r.push_back(*right.begin());
right.erase(right.begin());
left.erase(left.begin());
}
sl+=min(2*l.back(),L);
sr+=min(2*r.back(),L);
if(sl<sr){
ans+=sl;
for(int x:r) right.insert(x);
for(int x:l){
right.erase(right.find(L-x));
}
}
else{
ans+=sr;
for(int x:l) left.insert(x);
for(int x:r){
left.erase(left.find(L-x));
}
}
}
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... |