A conveyor belt has packages with weights weights[i]. Each day you load some consecutive packages on a ship with capacity C. You cannot split a package. Find the minimum ship capacity so all packages ship within days days.
weights=[1,2,3,4,5,6,7,8,9,10], days=515weights=[3,2,2,4,1,4], days=36weights=[1,2,3,1,1], days=43lo = max(weights) (ship must hold heaviest), hi = sum(weights) (ship all in 1 day)mid = lo + (hi-lo)/2needed days: pack each weight until overflow, then start new dayneeded ≤ D → feasible, try smaller: hi = midlo = mid + 1lo == hi → answer is lo
The feasibility function is monotone: if capacity C can ship in ≤ D days,
then any C' > C also can. This monotone property means a binary search over
capacities converges to the smallest feasible value.
The search space [max(w), sum(w)] is tight: below max(w) a single
package won't fit; above sum(w) one day suffices.