MicrosoftOA #5
Intern Tasks — Max Combined Reward Points
Estimated MediumJudge-ready
Topics (AI-labelled)Greedy
All tasks must be assigned: the first person does exactly k tasks and the second person does the rest. Each task is done exactly once. Find the maximum total reward.
Input
The first line contains n k (1≤n≤100000, 0≤k≤n), the second line contains the first person's n rewards, and the third line contains the second person's n rewards, each in 1..10000.
Output
Output a single integer, the answer.
Example 1
Input:
5 3
5 4 3 2 1
1 2 3 4 5
Output:
21
Example 2
Input:
1 0
1
9
Output:
9
Example 3
Input:
1 1
1
9
Output:
1
Example notes
Example 1: the second person doing everything earns 15, and the 3 largest differences are 4, 2, 0, for a total of 21.
Example 2: k=0, so all tasks go to the second person, earning 9.
Example 3: k=1, so the first person must do the task, earning 1; it cannot be withheld from them just because the reward is lower.
Editorial
Loading solution…