Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Subarray Value I

Try to solve the Maximum Total Subarray Value I problem.

Statement

You are given an integer array nums of length n and an integer k.

The value of a subarray is defined as the difference between the maximum element and the minimum element in that subarray.

You need to select k subarrays from nums. You are allowed to choose the same subarray multiple times.

Return the maximum possible total sum of the values of the chosen k subarrays.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤5×104\leq 5 \times 10^{4}

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Subarray Value I

Try to solve the Maximum Total Subarray Value I problem.

Statement

You are given an integer array nums of length n and an integer k.

The value of a subarray is defined as the difference between the maximum element and the minimum element in that subarray.

You need to select k subarrays from nums. You are allowed to choose the same subarray multiple times.

Return the maximum possible total sum of the values of the chosen k subarrays.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤5×104\leq 5 \times 10^{4}

  • 0≤0 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤105\leq 10^5