3689. Maximum Total Subarray Value I
You are given an integer array
numsof lengthnand an integerk.You need to choose exactly
knon-empty subarraysnums[l..r]ofnums. Subarrays may overlap, and the exact same subarray (samelandr) can be chosen more than once.The value of a subarray
nums[l..r]is defined as:max(nums[l..r]) - min(nums[l..r]).The total value is the sum of the values of all chosen subarrays.
Return the maximum possible total value you can achieve.
1 | class Solution { |