Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Subarray Value I

Maximum Total Subarray Value I asks you to choose k subarrays from an integer array, allowing repeats, and return the greatest total, where each subarray's value is its maximum minus minimum.

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

Maximum Total Subarray Value I asks you to choose k subarrays from an integer array, allowing repeats, and return the greatest total, where each subarray's value is its maximum minus minimum.

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