class Solution:
def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:
boxTypes = sorted(boxTypes, key = lambda x :x[1],reverse = True)
# print(boxTypes)
idx = 0
ans = 0
while truckSize > 0 and idx < len(boxTypes):
# print(truckSize,idx)
if truckSize - boxTypes[idx][0] >= 0:
ans += boxTypes[idx][0] * boxTypes[idx][1]
truckSize -= boxTypes[idx][0]
idx += 1
else:
ans += truckSize * boxTypes[idx][1]
truckSize = 0
return ans