Capacity To Ship Packages Within D Days
Real-world version: Kiln Load CeilingThe statement here is our own: the same inputs, outputs and technique.
A ceramics studio has one kiln and a queue of unfired pieces. The queue is given as masses, where masses[i] is the clay mass in grams of the piece standing at position i. Pieces leave the queue from the front only, so they are fired in exactly the listed order and are never rearranged.
The studio has booked sessions kiln runs. A single run takes some number of pieces off the front of the queue, which means each run fires one contiguous block of the queue, and it may take none at all. The kiln is rated for a load ceiling: the combined mass loaded into any one run may not exceed it.
Return the smallest load ceiling for which sessions runs are enough to fire the entire queue. A run is never split across sessions, and a piece is never fired twice.
Examples
Example 1
- Input
- masses = [9, 4, 6, 3, 8], sessions = 3
- Output
- 11
With a ceiling of 11 the runs can be 9 | 4, 6 | 3, 8. Dropping to 10 forces the trailing 3 and 8 apart, which needs a fourth run.
Example 2
- Input
- masses = [5, 5, 5, 5], sessions = 4
- Output
- 5
Four runs are booked for four pieces, so each run can hold one piece and the ceiling only has to cover the heaviest piece.
Example 3
- Input
- masses = [2, 4, 6, 1], sessions = 1
- Output
- 13
A single run must swallow the whole queue, so the ceiling equals the total mass of 13 grams.
Constraints
- 1 <= sessions <= masses.length <= 5 * 10^4
- 1 <= masses[i] <= 500
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 kiln_load_ceiling(masses: list[int], sessions: int) -> int:public int kilnLoadCeiling(int[] masses, int sessions)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 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