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
Inputreward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2
Output15
The 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
Inputreward1 = [1,1], reward2 = [1,1], k = 2
Output2
The 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

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate