diff --git a/cs/maximum-subsequence-score.cs b/cs/maximum-subsequence-score.cs new file mode 100644 index 0000000..d9f57f9 --- /dev/null +++ b/cs/maximum-subsequence-score.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +public class Solution { + public long MaxScore(int[] nums1, int[] nums2, int k) { + long prefixSum = 0, maxScore = 0; + + var heap = new PriorityQueue(); + foreach (var (num, mult) in nums1.Zip(nums2).OrderBy(key => key.Second).Reverse()) { + prefixSum += num; + heap.Enqueue(num, num); + + if (heap.Count == k) { + maxScore = Math.Max(maxScore, prefixSum * mult); + prefixSum -= heap.Dequeue(); + } + } + + return maxScore; + } +}