Maximum Bags With Full Capacity of Rocks
Real-world version: Crates Filled to the BrimThe statement here is our own: the same inputs, outputs and technique.
A yard holds n crates. Crate i takes capacity[i] bricks in total and already holds rocks[i] of them. A delivery brings additionalRocks more bricks, and each may be dropped into any crate that is not yet full.
Return the largest number of crates that can be filled to the brim.
Examples
Example 1
- Input
- capacity = [3, 6, 7], rocks = [1, 6, 2], additionalRocks = 5
- Output
- 2
The second crate is already full. Dropping 2 bricks into the first fills it, and the 3 bricks left do not cover the 5 the third crate still needs.
Example 2
- Input
- capacity = [4, 3, 2, 1], rocks = [0, 0, 0, 0], additionalRocks = 6
- Output
- 3
Filling the crates needing 1, 2 and 3 bricks uses all six bricks and fills three crates.
Example 3
- Input
- capacity = [5, 5, 5], rocks = [5, 5, 5], additionalRocks = 1
- Output
- 3
Every crate is already filled to the brim, so all three count and the delivery is not needed.
Constraints
- 1 <= capacity.length <= 50000
- capacity.length == rocks.length
- 1 <= capacity[i] <= 10^9
- 0 <= rocks[i] <= 10^9
- rocks[i] <= capacity[i] for every crate
- 1 <= additionalRocks <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def crates_filled(capacity: list[int], rocks: list[int], additionalRocks: int) -> int:public int cratesFilled(int[] capacity, int[] rocks, int additionalRocks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's