def capable(weights,pw) cnt=w=0 weights.each do|v| return 2**128 if v>pw if w+v>pw cnt+=1 w=0 end w+=v end cnt+1 end def ship_within_days(weights, days) (1..).bsearch{|v|capable(weights,v)<=days} end

이분탐색 언제까지 나오나 한번 보죠