제출 #526107

#제출 시각아이디문제언어결과실행 시간메모리
526107Deepesson쌀 창고 (IOI11_ricehub)C++17
26 / 100
517 ms2816 KiB
#include <bits/stdc++.h>
#include "ricehub.h"
typedef std::pair<long long,long long> pli;
pli custo(long long P,long long R,int X[],long long B){
    if(!P)return {0,0};
    std::vector<long long> vec;
    for(int i=0;i!=R;++i){
        long long dist = abs(X[i]-P);
        vec.push_back(dist);
    }
    std::sort(vec.begin(),vec.end());
    int res=0;
    for(auto&x:vec){
        if(x<=B){
            ++res;
            B-=x;
            continue;
        }
    }
    return {res,B};
}
int besthub(int R, int L, int X[], long long B)
{
   long long la=1,ra=L-1;
   while(ra-la>1){
        int m = (la+ra+1)/2;
        pli alpha = custo(m,R,X,B);
        pli beta = custo(m+1,R,X,B);
        if(alpha>=beta){
            ra=m;
        }else {la=m;}
   }
   return std::max(std::max(custo(la+1,R,X,B).first,custo(la,R,X,B).first),std::max(custo(1,R,X,B).first,custo(L,R,X,B).first));
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...