Submission #897535

#TimeUsernameProblemLanguageResultExecution timeMemory
897535ThylOneRice Hub (IOI11_ricehub)C++14
68 / 100
1072 ms3936 KiB
#include "ricehub.h" #include<bits/stdc++.h> using namespace std; vector<int> pos; long long budget; int limit; bool existWithT(int T){ long long sum = 0; for(int i=0;i<T;i++)sum+=pos[i]; auto computeScore = [&](int x,int l,int r){ long long re = 0; for(int i = l;i<=r;i++){ re+=abs(x-pos[i]); } return re; }; auto findGoodSegment = [&](int l,int r){ long long best = pos[(l+r)/2]; if(computeScore(best,l,r)<=budget)return true; return false; }; if(findGoodSegment(0,T-1))return true; for(int right=T;right<pos.size();right++){ sum-=pos[right-T]; sum+=pos[right]; if(findGoodSegment(right-T+1,right))return true; } return false; } int besthub(int R, int L, int X[], long long B) { budget = B; pos.resize(R); limit = L; for(int i = 0;i<R;i++){ pos[i] = X[i]; } sort(pos.begin(),pos.end()); int low = 1; int high = R; while ((high-low)>1){ int mid = (low+high)/2; if(existWithT(mid)){ low = mid; }else{ high = mid; } } if(existWithT(high)){ return high; }else{ return low; } }

Compilation message (stderr)

ricehub.cpp: In function 'bool existWithT(int)':
ricehub.cpp:28:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       for(int right=T;right<pos.size();right++){
      |                       ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...