← 返回 pinterest 的题目列表Split Array Largest Sum
类型:online_judge
Question
Given an array nums of non-negative integers and an integer m, split the array into m non-empty continuous subarrays.
Your goal is to minimize the largest sum among these m subarrays.
Return the minimum possible value of the largest subarray sum.
Input Format
The first line contains two integers n and m.
The second line contains n non-negative integers, representing nums.
Output Format
Print one integer: the minimized largest subarray sum after splitting the array into m non-empty continuous subarrays.
Constraints
1 <= n <= 1000
1 <= m <= min(50, n)
0 <= nums[i] <= 10^6
Example
Example 1
Input:
5 2
7 2 5 10 8
Output:
18
Explanation: The optimal split is [7,2,5] and [10,8], whose sums are 14 and 18. The largest sum is 18.
Example 2
Input:
5 2
1 2 3 4 5
Output:
9
Explanation: The optimal split is [1,2,3] and [4,5].
Example
Input
5 2
7 2 5 10 8
Output
18