Skip to content

Maximum Subsequence Score

MediumHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.

You get two arrays of the same length, nums1 and nums2, and a number k. Choose k indices. The score of your choice is

(sum of nums1 at the chosen indices) * (minimum of nums2 at the chosen indices)

Return the maximum possible score.

nums1 = [1, 3, 3, 2], nums2 = [2, 1, 3, 4], k = 3  →  12

Choosing indices 0, 2 and 3 gives (1 + 3 + 2) * min(2, 3, 4) = 6 * 2 = 12.

Constraints

  • 1 <= k <= n <= 10^5 (n is the length of both arrays)
  • 0 <= nums1[i], nums2[i] <= 10^5