Loading...
You are given an integer array nums and integers groups and m, with groups * m <= nums.length.
Split nums into exactly groups contiguous blocks that together cover the whole array, where every block contains at least m elements.
Each block scores the sum of its m largest elements. Return the maximum possible total score over all valid splits.
Input: nums = [1,3,5,2,7,1,5,9], groups = 3, m = 2
Output: 31
Explanation: Split as [1,3,5] | [2,7] | [1,5,9]. Block scores: (3+5) + (2+7) + (5+9) = 8 + 9 + 14 = 31. No split does better.
Input: nums = [4,4,4,4], groups = 2, m = 2
Output: 16
Explanation: The only split is [4,4] | [4,4]; every element is counted.
mgroupsgroups ⋅ m ≤ nums.length ≤105nums[i] ≤104Click "Run" to test with sample cases or "Submit" to run all tests.