Medium
,Array
,Greedy
,Heap
,Sorting
2542. Maximum Subsequence Score
You are given two 0-indexed integer arrays nums1
and nums2
of equal length n
and a positive integer k
. You must choose a subsequence of indices from nums1
of length k
.
For chosen indices i0
, i1
, …, ik - 1
, your score is defined as:
nums2
.(nums1[i0] + nums1[i1] +...+ nums1[ik - 1]) * min(nums2[i0] , nums2[i1], ... ,nums2[ik - 1])
.Return the maximum possible score.
A subsequence of indices of an array is a set that can be derived from the set {0, 1, ..., n-1}
by deleting some or no elements.
Example 1:
Example 2:
Constraints:
n
== nums1.length
== nums2.length
n
<= 105nums1[i]
, nums2[j]
<= 105k
<= n
Jerry WuWed, May24, 2023
Yen-Chi ChenWed, May 24, 2023
Ron ChenWed, May 24, 2023