classSolution{public:intminEatingSpeed(vector<int>&piles,inth){intl=1;intr=*max_element(begin(piles),end(piles));while(l<r){constintm=(l+r)/2;if(eatHours(piles,m)<=h)r=m;elsel=m+1;}returnl;}private:// Hours to eat all piles with speed minteatHours(constvector<int>&piles,intm){returnaccumulate(begin(piles),end(piles),0,[&](intsubtotal,intpile){returnsubtotal+(pile-1)/m+1;// Ceil(pile / m)});}};
classSolution{publicintminEatingSpeed(int[]piles,inth){intl=1;intr=Arrays.stream(piles).max().getAsInt();while(l<r){finalintm=(l+r)/2;if(eatHours(piles,m)<=h)r=m;elsel=m+1;}returnl;}// Hours to eat all piles with speed mprivateinteatHours(int[]piles,intm){returnArrays.stream(piles).reduce(0,(subtotal,pile)->subtotal+(pile-1)/m+1);// Math.ceil(pile / m)}}
classSolution:defminEatingSpeed(self,piles:List[int],h:int)->int:l=1r=max(piles)# Hours to eat all piles with speed mdefeatHours(m:int)->int:returnsum((pile-1)//m+1forpileinpiles)whilel<r:m=(l+r)//2ifeatHours(m)<=h:r=melse:l=m+1returnl