class Solution:
def shipWithinDays(self, weights: List[int], days: int) -> int:
n=len(weights)
r=sum(weights)
l=max(weights)
@cache
def check(capacity):
i=0
d=0
while i<n:
d+=1
tank=capacity
while i<n and tank>=weights[i]:
tank-=weights[i]
i+=1
return d
while 1:
m=(l+r)//2
if check(m)==days and check(m-1)<days:
return m
elif check(m)<=days:
r=m
elif check(m)>days:
l=m
if r-l<=1:
if check(l)<=days:
return l
return r
注意最小的left