A warehouse ships boxes on a truck that can carry at most T boxes in total. There are m box types; type i has count[i] identical boxes available, and every box of that type holds units[i] units of goods. You may load any boxes you like, from any types, up to the T-box limit.
Return the maximum total number of units you can load.
Line 1: two integers m and T — the number of box types and the truck's box capacity.
Line 2 .. m+1: each line has two integers count[i] and units[i] for one box type.
A single integer: the maximum total units that can be loaded without exceeding T boxes.
Example 1
Input
3 4 1 3 2 2 3 1
Expected
8
Explanation
Capacity is 4 boxes. Take the one box worth 3, then both boxes worth 2 (total 3 boxes so far, 7 units), then one box worth 1. That is 4 boxes and 3 + 2 + 2 + 1 = 8 units, the maximum.
Example 2
Input
2 10 2 5 3 4
Expected
22
Explanation
Only 5 boxes exist but capacity is 10, so load them all: 2*5 + 3*4 = 22 units.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →