##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The main difficulty is that the array is circular. If the array were linear, this would be the classical problem of splitting an array into non-empty subarrays while minimizing the maximum subarray sum.
Here we can still use the same high-level idea.
Suppose we guess that the answer is at most .
Now the question becomes:
Can we cut the circle into at most non-empty contiguous parts, such that the sum of each part is at most ?
We use "at most " instead of "exactly " because all are positive.
If we can split the circle into parts, then we can split some of those parts further until we have exactly parts. Since every new part has smaller or equal sum than the original part, the maximum cost will not increase.
Also, because , this splitting process is always possible.
So for a fixed , it is enough to check whether the circle can be covered using at most parts, each with sum at most .