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.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.
height=3, paces=[2, 2, 2] → 2
Each worker removes one meter in 2 seconds, all at the same time.
height=4, paces=[5] → 50
height=6, paces=[1, 4]
12
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.