In the shipping docks of Prime City, the Harbor Master must split a sequence of cargo containers into m contiguous groups, minimizing the maximum total weight of any group. This is a classic binary search on the answer problem. "Binary search on the capacity," the Harbor Master says. "The minimum possible capacity is max(array) (each element in its own group won't help if one is bigger). The maximum is sum(array) (all in one group). Binary search between these bounds, checking if a given capacity can split the array into at most m groups." Given an array of N non-negative integers and an integer m, split the array into m contiguous subarrays such that the largest sum among the subarrays is minimized. Output this minimized largest sum. Constraints: 1 <= N <= 1000, 0 <= array[i] <= 10^6, 1 <= m <= N Input: 5 7 2 5 10 8 2 Output: 18 Input: 3 1 2 3 2 Output: 3
Constraints:
1 <= N <= 1000, 0 <= array[i] <= 10^6, 1 <= m <= N
Tags:
