Submission #291686

#TimeUsernameProblemLanguageResultExecution timeMemory
291686REALITYNBBoxes with souvenirs (IOI15_boxes)C++14
35 / 100
1 ms384 KiB
#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() ; 
                }
                kk= k  ; 
            }
            break ; 
        }
        else if(sh.empty()){
            while(fh.size()){
                ans+=fh.back()*2 ; 
                while(kk--&&fh.size()){
                    fh.pop_back() ; 
                }
                kk=k ; 
            }
            break ; 
        }
        if(sh.back()*2+fh.back()*2<=l||k==1){
              while(fh.size()){
                ans+=fh.back()*2 ; 
                while(kk--&&fh.size()){
                    fh.pop_back() ; 
                }
                kk= k ; 
            }
            kk = k ; 
                        while(sh.size()){
                ans+=sh.back()*2 ; 
                while(kk--&&sh.size()){
                    sh.pop_back() ; 
                }
                kk= k ; 
            }
            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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...