3077. Maximum Strength of K Disjoint Subarrays
You are given a 0-indexed array of integers
nums
of lengthn
, and a positive odd integerk
.The strength of
x
subarrays is defined asstrength = sum[1] * x - sum[2] * (x - 1) + sum[3] * (x - 2) - sum[4] * (x - 3) + ... + sum[x] * 1
wheresum[i]
is the sum of the elements in theith
subarray. Formally, strength is sum of(-1)i+1 * sum[i] * (x - i + 1)
over alli
‘s such that1 <= i <= x
.You need to select
k
disjoint subarrays fromnums
, such that their strength is maximum.Return the maximum possible strength that can be obtained.
Note that the selected subarrays don’t need to cover the entire array.
c++
1 |
|