Minimum Number of Seconds to Make Mountain Height Zero
Real-world version: Clearing the Spoil Heap TogetherThe statement here is our own: the same inputs, outputs and technique.
A spoil heap holds mountainHeight units. Digger i works at a rate given by workerTimes[i]: clearing x units takes that digger workerTimes[i] * x * (x + 1) / 2 seconds in total.
Every digger works at the same time as the others, and between them they must clear the whole heap. Return the fewest seconds until the heap is gone, which is the longest any one digger has to work.
Examples
Example 1
- Input
- mountainHeight = 10, workerTimes = [2, 2]
- Output
- 30
Splitting the ten units five apiece has each digger spend 2 times 15, which is 30 seconds, and no other split of the heap finishes sooner.
Example 2
- Input
- mountainHeight = 10, workerTimes = [4]
- Output
- 220
The single digger must clear all ten units, which costs 4 times 55.
Example 3
- Input
- mountainHeight = 3, workerTimes = [1, 1000000]
- Output
- 6
The slow digger is worth one unit at most: taking one costs it a million seconds, while the fast digger clearing all three costs only six. Leaving it idle is better, so the answer is the fast digger's six seconds.
Constraints
- 1 <= mountainHeight <= 10^5
- 1 <= workerTimes.length <= 10^4
- 1 <= workerTimes[i] <= 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 min_number_of_seconds(mountainHeight: int, workerTimes: list[int]) -> int:public long minNumberOfSeconds(int mountainHeight, int[] workerTimes)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 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
More on the same topics
- Sell Diminishing-Valued Colored BallsReal-world version: Rare Poster RevenueMedium
- Avoid Flood in The CityReal-world version: Draining the Basins Before They SpillMedium
- Maximum Number of Groups With Increasing LengthReal-world version: How Many Growing Batches Can Be FilledHard
- Missing NumberReal-world version: Unclaimed Badge NumberEasy