Problem · Array
Maximum Reward Points
Learn this problemProblem statement
Two interns are assigned to complete a total of n tasks. Each task must be completed by exactly one of them. For task i, the first intern earns reward_1[i] points and the second intern earns reward_2[i] points.
The first intern must complete exactly k tasks, which may be any k of the n tasks. The second intern completes the remaining tasks. Return the maximum possible combined reward points.
Function
getMaximumRewardPoints(k: int, reward_1: int[], reward_2: int[]) → intExamples
Example 1
k = 3reward_1 = [5, 4, 3, 2, 1]reward_2 = [1, 2, 3, 4, 5]return = 21The first intern completes the first three tasks and earns 5 + 4 + 3 points. The second intern completes the remaining two tasks and earns 4 + 5 points. Their combined reward is 5 + 4 + 3 + 4 + 5 = 21, which is the maximum possible.
Constraints
- 1 ≤ n ≤ 10^5
- 0 ≤ k ≤ n
- 1 ≤ reward_1[i] ≤ 10^4
- 1 ≤ reward_2[i] ≤ 10^4