Practice Choose K Elements With Maximum Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
For each index i, consider indices j where nums1[j] is strictly smaller than nums1[i]. Select at most k of their corresponding nums2[j] values to maximize the sum. Return this maximum sum for every i in original index order.
Source: Choose K Elements With Maximum Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums1 = [4,2,1,5,3], nums2 = [10,20,30,40,50], k = 2
Output
[80,30,0,80,50]
# Example 2
Input
nums1 = [2,2,2,2], nums2 = [3,1,2,3], k = 1
Output
[0,0,0,0]
Constraints
n == nums1.length == nums2.length
1 <= n <= 10^5
1 <= nums1[i], nums2[i] <= 10^6
1 <= k <= n
Related LeetCode Problems
Practice more problems similar to Choose K Elements With Maximum Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.