You are given an array of integers nums with length n, and a positive odd integer k.
Select exactly k disjoint subarrays sub₁, sub₂, ..., subₖ from nums such that the last element of subᵢ appears before the first element of subᵢ₊₁ for all 1 ≤ i ≤ k-1.
The goal is to maximize their combined strength. The strength of the selected subarrays is defined as:
strength = k × sum(sub₁) - (k-1) × sum(sub₂) + (k-2) × sum(sub₃) - ... - 2 × sum(subₖ₋₁) + sum(subₖ)
where sum(subᵢ) is the sum of the elements in the i-th subarray.
Return the maximum possible strength that can be obtained from selecting exactly k disjoint subarrays from nums.
Note: The chosen subarrays don't need to cover the entire array.
Input & Output
Constraints
- 1 ≤ nums.length ≤ 104
- 1 ≤ k ≤ nums.length
- k is odd
- -109 ≤ nums[i] ≤ 109