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[]){
#define int long long
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)) ;
#define sz(a) ((int)a.size())
int cur = 0 ;
int ans = 0 ;
for(int i=sz(sh)-1;i>-1;i-=k) cur+=sh[i]*2 ;
for(int i=sz(fh)-1;i>-1;i-=k) cur+=fh[i]*2 ;
for(int i=0;i<=n;i++){
int kk = k ;
int mx = 0 , mxx = 0 ;
while(kk--){
if(fh.empty()&&sh.empty()) break ;
if(sh.empty()){
mx = max(mx,fh.back()) ;
fh.pop_back() ;
continue ;
}
if(fh.empty()){
mxx = max(mxx,sh.back()) ;
sh.pop_back() ;
continue ;
}
if(fh.back()>=sh.back()){
mx=max(mx,fh.back()) ;
fh.pop_back() ;
}
else{
mxx = max(mxx,sh.back()) ;
sh.pop_back() ;
}
}
cur+=l ;
cur+= (mx+mxx)*-2 ;
ans= min(ans,cur) ;
}
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... |