以Unite多的箱子为优先放置。直到用完Truck size或者没有箱子可用。
class Solution:
def maximumUnits(self, boxTypes: List[List[int]], truckSize: int) -> int:
container = []
for box, units in boxTypes:
container.append((box, units))
container.sort(key = lambda x:(x[1]), reverse = True)
#print(container)
res = 0
while truckSize > 0:
if len(container):
numofbox, unites = container.pop(0)
else:
break
if truckSize >= numofbox:
res += numofbox * unites
truckSize -= numofbox
else:
res += truckSize*unites
truckSize = 0
break
return res