Description

You are assigned to put boxes onto a truck with limited capacity. Given boxTypes where boxTypes[i] = [numberOfBoxes, numberOfUnitsPerBox], return the maximum total number of units that can be put on the truck.

Examples

Input:boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4
Output:8
Explanation:

Take 1 of type1 (3 units), 2 of type2 (4 units), 1 of type3 (1 unit) = 8.

Input:boxTypes = [[1]], truckSize = 4
Output:1
Explanation:

Only one box type is available. The truck can hold up to 4 boxes, but only 1 box exists, contributing 1 unit.

Input:boxTypes = [[5,10],[2,5],[4,1],[3,9]], truckSize = 10
Output:87
Explanation:

Sort by units per box descending: [5,10], [3,9], [2,5], [4,1]. Take all 5 boxes of type 1 (50 units), all 3 of type 2 (27 units), all 2 of type 3 (10 units). Total: 5+3+2=10 boxes, 50+27+10=87 units.

Constraints

  • 1 ≤ boxTypes.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!