Mice and Cheese
There are two mice and n different types of cheese, and each type of cheese should be eaten by exactly one mouse.
A point of the cheese with index i (0-indexed) is:
reward1[i]if the first mouse eats it.reward2[i]if the second mouse eats it.
You are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.
Return the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.
Example 1
Input
reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2Output
15The first mouse eats cheese types 2 and 3, while the second mouse eats types 0 and 1, giving total points 4 + 4 + 3 + 4 = 15, which is maximum.
Example 2
Input
reward1 = [1,1], reward2 = [1,1], k = 2Output
2The first mouse eats both cheese types and the second mouse eats none, giving total points 1 + 1 = 2, which is maximum.
Constraints
- 1 <= n == reward1.length == reward2.length <= 10^5
- 1 <= reward1[i], reward2[i] <= 1000
- 0 <= k <= n