left
to the maximum weight in weights
and right
to the sum of all weights in weights
.left
is less than right
:
a. Calculate mid
as the average of left
and right
.
b. Check if it's possible to ship all packages within days
using mid
as the ship's capacity.
c. If it is possible, set right
to mid
.
d. If it is not possible, set left
to mid + 1
.left
as the minimum capacity required.