2279. Maximum Bags With Full Capacity of Rocks
class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
answer = 0
capacity_bag = []
for i in range(len(capacity)):
if capacity[i] == rocks[i]:
answer += 1
continue
capacity_bag.append(capacity[i] - rocks[i])
capacity_bag.sort()
for x in capacity_bag:
if additionalRocks < x:
break
additionalRocks -= x
answer += 1
return answer
class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
remain_capacity = sorted([c - r for c, r in zip(capacity, rocks)])
answer = 0
for x in remain_capacity:
if additionalRocks < x:
break
additionalRocks -= x
answer += 1
return answer