1710. Maximum Units on a Truck
On This Page
class Solution:
def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:
cnt = [0] * 1001
for a, b in boxTypes:
cnt[b] += a
res = 0
for b in range(1000, 0, -1):
a = cnt[b]
if a:
res += b * min(truckSize, a)
truckSize -= a
if truckSize <= 0:
break
return res