Ctrl K

A Crew Levels a Hill

Medium
A hill height meters tall has to be dug down to nothing. A crew works on it, everyone at the same time and independently. Worker i with pace paces[i] spends paces[i] seconds on the first meter they remove, 2 · paces[i] on the second, 3 · paces[i] on the third, and so on: removing x meters costs them paces[i] · (1 + 2 + … + x) seconds. Split the meters among the workers (some may get none) so the hill is gone as early as possible. Return the minimum number of seconds until the last worker finishes.
Example 1
height=6, paces=[1, 4] → 12

The first worker removes 4 meters in 1 + 2 + 3 + 4 = 10 seconds, the second removes 2 meters in 4 + 8 = 12 seconds. It cannot be faster: giving the first worker 5 meters would take him 15 seconds.

Example 2
height=3, paces=[2, 2, 2] → 2

Each worker removes one meter in 2 seconds, all at the same time.

Example 3
height=4, paces=[5] → 50
Constraints
  • 1 ≤ height ≤ 10⁵
  • 1 ≤ len(paces) ≤ 10⁴
  • 1 ≤ paces[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrices That Fade With Each Sale MediumA Plan for Draining Ponds MediumSame Prizes, Different Tastes MediumShrink the Squared Gaps MediumEver-Growing Teams Medium
loading Python…
Input
height=6, paces=[1, 4]
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.