Skip to content
This repository was archived by the owner on Jul 30, 2023. It is now read-only.

Commit 5ba127b

Browse files
authored
Create 2542-maximum-subsequence-score.kt
1 parent 85d1f52 commit 5ba127b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
fun maxScore(nums1: IntArray, nums2: IntArray, k: Int): Long {
3+
val nums = nums1.zip(nums2).sortedWith(compareBy({ -it.second }))
4+
val minHeap = PriorityQueue<Int>()
5+
6+
var sum = 0L
7+
var res = 0L
8+
for ((n1, n2) in nums) {
9+
sum += n1
10+
minHeap.add(n1)
11+
12+
if (minHeap.size > k)
13+
sum -= minHeap.poll()
14+
if (minHeap.size == k)
15+
res = maxOf(res, sum * n2)
16+
}
17+
18+
return res
19+
}
20+
}

0 commit comments

Comments
 (0)