All problems
0914MediumArrayMathBinary SearchGreedyHeap (Priority Queue)

Clearing the Spoil Heap Together

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3296Minimum Number of Seconds to Make Mountain Height Zero

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def min_number_of_seconds(mountainHeight: int, workerTimes: list[int]) -> int:
Java
public long minNumberOfSeconds(int mountainHeight, int[] workerTimes)
September 7
Apply