class Solution:
def shipWithinDays(self, weights: List[int], D: int) -> int:
left, right = max(weights), sum(weights)
def available(num, limit):
count, current = 0, 0
for item in weights:
if current + item < num:
current += item
elif current + item == num:
count += 1
current = 0
else:
count += 1
current = item
count += 1 if current > 0 else 0
return count <= limit
while left <= right:
mid = (left + right) // 2
if available(mid, D):
right = mid - 1
else:
left = mid + 1
return left