Task Completion

Task Completion

FULLTIME

Two interns at AOneCode are teamed up to complete a total of n tasks. Each task is to be completed by either of the two interns. Both interns have their reward points defined, where the first intern gains reward_1[i] points for completing the ith th task, while the second intern gains reward_2[i] points for completing the ith th task.

Since the interns work as a team, they wish to maximize the total reward points gained by both of them combined. Find the maximum combined reward points that can be gained if the first intern has to complete k tasks, and the second intern completes the remaining tasks.

Note: The k tasks completed by the first intern could be any amongst the n tasks.


Function Description

Complete the function getMaximumRewardPoints in the editor.

getMaximumRewardPoints has the following parameters:

  1. int k : the number of tasks that have to be completed by intern 1
  2. int reward_1[n] : the reward points earned by intern 1 for each task
  3. int reward_2[n] : the reward points earned by intern 2 for each task


Returns

int: the maximum possible combined reward points when intern 1 completes exactly k tasks


Example 1 :

Input: k = 3, reward_1 = [5, 4, 3, 2, 1], reward_2 = [1, 2, 3, 4, 5]
Output: 21
Explanation: Intern 1 has to complete 3 tasks, while intern 2 has to complete the remaining 2 tasks. The reward points for each task are the same for both the interns, so any tasks can be picked up by either intern. Total reward points = 1 + 2 + 3 + 2 = 8.


Example 2 :

Input: k = 2, reward_1 = [2, 3, 4, 2], reward_2 = [1, 1, 1, 1]
Output: 9
Explanation: Intern 1 has to complete 2 tasks, while intern 2 has to complete the remaining 2 tasks. In order to maximize the total reward points, intern 1 completes the second and third tasks, while intern 2 completes the first and fourth tasks. Total reward points gained = 4 + 3 (from intern 1) + 1 + 1 (from intern 2) = 9.


Constraints:

  • 1 ≤ n ≤ 105
  • 0 ≤ k ≤ n
  • 1 ≤ reward_1[j] ≤ 104
  • 1 ≤ reward_2[j] ≤ 104



  • Get one-to-one training from Google Facebook engineers

    Top-notch Professionals

    Learn from Facebook and Google senior engineers interviewed 100+ candidates.
    Most recent interview questions and system design topics gathered from aonecode alumnus.
    One-to-one online classes. Get feedbacks from real interviewers.

    Customized Private Class

    Already a coding expert? - Advance straight to hard interview topics of your interest.
    New to the ground? - Develop basic coding skills with your own designated mentor.
    Days before interview? - Focus on most important problems in target company question bank.