remaining_capacity
to store the remaining capacity of each bag.capacity[i] - rocks[i]
and store it in remaining_capacity
.remaining_capacity
array in ascending order.full_bags
to 0 to keep track of the number of bags filled to full capacity.remaining_capacity
array:
a. For each cap
in remaining_capacity
, check if additionalRocks
is greater than or equal to cap
.
b. If yes, increment full_bags
, decrement additionalRocks
by cap
, and continue to the next bag.
c. If no, break the loop as we cannot fill any more bags.full_bags
.