left
as the minimum sweetness of any chunk and right
as the total sweetness divided by k + 1
.mid
as (left + right + 1) / 2
.
b. Use a greedy approach to check if it's possible to cut the bar into k + 1
pieces where each piece has at least mid
sweetness.
c. If it's possible, update left
to mid
. Otherwise, update right
to mid - 1
.left
equals right
, which will be the maximum possible minimum sweetness value.left
as the final answer.