left
to 1 and right
to the maximum value in quantities
.left
is less than or equal to right
:
a. Calculate mid
as the average of left
and right
.
b. Initialize a variable requiredStores
to 0.
c. Iterate over each quantity in quantities
:
i. Increment requiredStores
by the ceiling of the current quantity divided by mid
.
d. If requiredStores
is less than or equal to n
, update right
to mid - 1
(try a smaller x
).
e. Otherwise, update left
to mid + 1
(try a larger x
).left
as the minimum possible x
.