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 <bits/stdc++.h>
#define all(a) a.begin(),a.end()
using namespace std;
long long delivery(int n,int k , int l , int positionss[]){
vector<int> positions ;
for(int i=0;i<n;i++) positions.push_back(positionss[i]) ;
vector<int> fh , sh ;
for(int& x : positions){
if(x<=l-x){
fh.push_back(x) ;
}
else sh.push_back(l-x) ;
}
sort(all(fh)) ;
sort(all(sh)) ;
long long ans = 0 ;
while(fh.size()||sh.size()){
int kk = k ;
if(fh.empty()){
while(sh.size()){
ans+=sh.back()*2 ;
while(kk--&&sh.size()){
sh.pop_back() ;
}
}
break ;
}
else if(sh.empty()){
while(fh.size()){
ans+=fh.back()*2 ;
while(kk--&&fh.size()){
fh.pop_back() ;
}
}
break ;
}
if(sh.back()*2+fh.back()*2<=l){
while(fh.size()){
ans+=fh.back()*2 ;
while(kk--&&fh.size()){
fh.pop_back() ;
}
}
kk = k ;
while(sh.size()){
ans+=sh.back()*2 ;
while(kk--&&sh.size()){
sh.pop_back() ;
}
}
break ;
}
ans+=l ;
while(kk--){
if(sh.size()==0&&fh.empty()) break ;
if(fh.empty()){
sh.pop_back() ;
continue ;
}
if(sh.empty()){
fh.pop_back() ;
continue ;
}
if(fh.back()<=sh.back()) sh.pop_back() ;
else fh.pop_back() ;
}
}
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... |