Class Solution
java.lang.Object
g2201_2300.s2279_maximum_bags_with_full_capacity_of_rocks.Solution
2279 - Maximum Bags With Full Capacity of Rocks.<p>Medium</p>
<p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</code> rocks. You are also given an integer <code>additionalRocks</code>, the number of additional rocks you can place in <strong>any</strong> of the bags.</p>
<p>Return <em>the <strong>maximum</strong> number of bags that could have full capacity after placing the additional rocks in some bags.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>Place 1 rock in bag 0 and 1 rock in bag 1.</p>
<p>The number of rocks in each bag are now [2,3,4,4].</p>
<p>Bags 0, 1, and 2 have full capacity.</p>
<p>There are 3 bags at full capacity, so we return 3.</p>
<p>It can be shown that it is not possible to have more than 3 bags at full capacity.</p>
<p>Note that there may be other ways of placing the rocks that result in an answer of 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>Place 8 rocks in bag 0 and 2 rocks in bag 2.</p>
<p>The number of rocks in each bag are now [10,2,2].</p>
<p>Bags 0, 1, and 2 have full capacity.</p>
<p>There are 3 bags at full capacity, so we return 3.</p>
<p>It can be shown that it is not possible to have more than 3 bags at full capacity.</p>
<p>Note that we did not use all of the additional rocks.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == capacity.length == rocks.length</code></li>
<li><code>1 <= n <= 5 * 10<sup>4</sup></code></li>
<li><code>1 <= capacity[i] <= 10<sup>9</sup></code></li>
<li><code>0 <= rocks[i] <= capacity[i]</code></li>
<li><code>1 <= additionalRocks <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintmaximumBags(int[] capacity, int[] rocks, int additionalRocks)
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maximumBags
public int maximumBags(int[] capacity, int[] rocks, int additionalRocks)
-