Maximum Bags With Full Capacity of Rocks

You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The i^th bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an integer additionalRocks, the number of additional rocks you can place in any of the bags.

Return the maximum number of bags that could have full capacity after placing the additional rocks in some bags.

Example 1
Inputcapacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
Output3
Place 1 rock in bag 0 and 1 rock in bag 1 so bags 0, 1, and 2 have full capacity, and it is not possible to have more than 3 full bags.
Example 2
Inputcapacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
Output3
Place 8 rocks in bag 0 and 2 rocks in bag 2 so all three bags have full capacity, even though not all additional rocks are used.

Constraints

  • n == capacity.length == rocks.length
  • 1 <= n <= 5 * 10^4
  • 1 <= capacity[i] <= 10^9
  • 0 <= rocks[i] <= capacity[i]
  • 1 <= additionalRocks <= 10^9

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