Maximum Units on a Truck
Real-world version: Seedling Trolley LoadThe statement here is our own: the same inputs, outputs and technique.
A nursery wheels plant trays out to the loading dock on a single trolley.
You are given trayTypes, where trayTypes[i] = [count_i, seedlings_i] means the nursery has count_i trays of type i on hand and each of those trays holds exactly seedlings_i seedlings.
The trolley has room for trolleySlots trays altogether. You may put on any mix of types, taking no more of a type than the nursery has, and you are free to leave slots empty.
Return the greatest number of seedlings a single trolley run can carry.
Examples
Example 1
- Input
- trayTypes = [[2,4],[3,7],[1,2]], trolleySlots = 4
- Output
- 25
Loading all three trays of type 1 at 7 seedlings each and one tray of type 0 at 4 seedlings uses 4 slots and carries 21 + 4 = 25 seedlings.
Example 2
- Input
- trayTypes = [[6,3],[2,9]], trolleySlots = 2
- Output
- 18
Only 2 slots exist, and loading both trays of type 1 carries 9 + 9 = 18 seedlings.
Example 3
- Input
- trayTypes = [[1,5],[2,8]], trolleySlots = 10
- Output
- 21
Every tray the nursery has fits, so all 3 trays go on and carry 5 + 8 + 8 = 21 seedlings, leaving 7 slots empty.
Example 4
- Input
- trayTypes = [[4,6],[5,6],[2,1]], trolleySlots = 7
- Output
- 42
Types 0 and 1 both hold 6 seedlings per tray, and taking all 4 trays of type 0 plus 3 trays of type 1 fills the 7 slots for 42 seedlings.
Constraints
- 1 <= trayTypes.length <= 1000
- trayTypes[i].length == 2
- 1 <= count_i, seedlings_i <= 1000
- 1 <= trolleySlots <= 10^6
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def maximum_units(trayTypes: list[list[int]], trolleySlots: int) -> int:public int maximumUnits(int[][] trayTypes, int trolleySlots)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Assign CookiesReal-world version: Scratch Space HandoutEasy
- Array PartitionReal-world version: Doubles for the Club RegattaEasy
- Earliest Finish Time for Land and Water Rides IReal-world version: Forge and Kiln BookingEasy
- Maximize Sum Of Array After K NegationsReal-world version: Largest Ledger Total After Forced Sign FlipsEasy