제출 #291701

#제출 시각아이디문제언어결과실행 시간메모리
291701REALITYNB선물상자 (IOI15_boxes)C++14
0 / 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[]){
    #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= max(ans,cur) ; 
    }   
    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...