Package g2601_2700.s2611_mice_and_cheese
Class Solution
java.lang.Object
g2601_2700.s2611_mice_and_cheese.Solution
2611 - Mice and Cheese.<p>Medium</p>
<p>There are two mice and <code>n</code> different types of cheese, each type of cheese should be eaten by exactly one mouse.</p>
<p>A point of the cheese with index <code>i</code> ( <strong>0-indexed</strong> ) is:</p>
<ul>
<li><code>reward1[i]</code> if the first mouse eats it.</li>
<li><code>reward2[i]</code> if the second mouse eats it.</li>
</ul>
<p>You are given a positive integer array <code>reward1</code>, a positive integer array <code>reward2</code>, and a non-negative integer <code>k</code>.</p>
<p>Return <em><strong>the maximum</strong> points the mice can achieve if the first mouse eats exactly</em> <code>k</code> <em>types of cheese.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2</p>
<p><strong>Output:</strong> 15</p>
<p><strong>Explanation:</strong> In this example, the first mouse eats the 2<sup>nd</sup> (0-indexed) and the 3<sup>rd</sup> types of cheese, and the second mouse eats the 0<sup>th</sup> and the 1<sup>st</sup> 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.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> reward1 = [1,1], reward2 = [1,1], k = 2</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> In this example, the first mouse eats the 0<sup>th</sup> (0-indexed) and 1<sup>st</sup> 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.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n == reward1.length == reward2.length <= 10<sup>5</sup></code></li>
<li><code>1 <= reward1[i], reward2[i] <= 1000</code></li>
<li><code>0 <= k <= n</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
miceAndCheese
(int[] firstReward, int[] seondReward, int numberOfTypesOfCheeseForFirstMouse)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
miceAndCheese
public int miceAndCheese(int[] firstReward, int[] seondReward, int numberOfTypesOfCheeseForFirstMouse)
-