Loading
Loading
A relief warehouse ships supplies in crates. The stock list has one row per kind of crate: how many crates of that kind are available, and how many ration units each of those crates holds.
The truck can carry at most capacity crates, of any mix of kinds. Return the most ration units it can carry.
stock = [[5, 10], [2, 5], [4, 7], [3, 9]], capacity = 10kinds by units: 10, 9, 7, 5sort by value per cratetake 5 crates × 10 = 505 slots lefttake 3 crates × 9 = 272 slots lefttake 2 crates × 7 = 14truck full: 50 + 27 + 14 = 9191Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
| 0 | 1 | 3 |
|---|---|---|
| 1 | 2 | 2 |
| 2 | 3 | 1 |
Take the 3-unit crate, both 2-unit crates and one 1-unit crate: 3 + 4 + 1 = 8.
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(k log k) time · O(k) space
Input. Run your code to watch it work on this input, one line at a time.
| 0 | 1 | 3 |
|---|---|---|
| 1 | 2 | 2 |
| 2 | 3 | 1 |
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
| 0 | 5 | 10 |
|---|---|---|
| 1 | 2 | 5 |
| 2 | 4 | 7 |
| 3 | 3 | 9 |
50 + 27 + 14 = 91.