#2611
Mice and Cheese
specialist · 905 · lc medium +31 · verified · 48.3% accepted · 675 likes · top 34%
Description
There are n cheese types and two mice. Each cheese must be eaten by exactly one mouse: cheese i gives the first mouse reward1[i] points or the second mouse reward2[i] points. The first mouse must eat exactly k cheeses. Return the maximum total points.
Example 1:
Input: reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2
Output: 15
Explanation: In this example, the first mouse eats the 2nd (0-indexed) and the 3rd types of cheese, and the second mouse eats the 0th and the 1st types of cheese.
The total points are 4 + 4 + 3 + 4 = 15.
It can be proven that 15 is the maximum total points that the mice can achieve.
Example 2:
Input: reward1 = [1,1], reward2 = [1,1], k = 2
Output: 2
Explanation: In this example, the first mouse eats the 0th (0-indexed) and 1st types of cheese, and the second mouse does not eat any cheese.
The total points are 1 + 1 = 2.
It can be proven that 2 is the maximum total points that the mice can achieve.
Code
1
2
3