|
| 1 | +3296\. Minimum Number of Seconds to Make Mountain Height Zero |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +You are given an integer `mountainHeight` denoting the height of a mountain. |
| 6 | + |
| 7 | +You are also given an integer array `workerTimes` representing the work time of workers in **seconds**. |
| 8 | + |
| 9 | +The workers work **simultaneously** to **reduce** the height of the mountain. For worker `i`: |
| 10 | + |
| 11 | +* To decrease the mountain's height by `x`, it takes `workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x` seconds. For example: |
| 12 | + * To reduce the height of the mountain by 1, it takes `workerTimes[i]` seconds. |
| 13 | + * To reduce the height of the mountain by 2, it takes `workerTimes[i] + workerTimes[i] * 2` seconds, and so on. |
| 14 | + |
| 15 | +Return an integer representing the **minimum** number of seconds required for the workers to make the height of the mountain 0. |
| 16 | + |
| 17 | +**Example 1:** |
| 18 | + |
| 19 | +**Input:** mountainHeight = 4, workerTimes = [2,1,1] |
| 20 | + |
| 21 | +**Output:** 3 |
| 22 | + |
| 23 | +**Explanation:** |
| 24 | + |
| 25 | +One way the height of the mountain can be reduced to 0 is: |
| 26 | + |
| 27 | +* Worker 0 reduces the height by 1, taking `workerTimes[0] = 2` seconds. |
| 28 | +* Worker 1 reduces the height by 2, taking `workerTimes[1] + workerTimes[1] * 2 = 3` seconds. |
| 29 | +* Worker 2 reduces the height by 1, taking `workerTimes[2] = 1` second. |
| 30 | + |
| 31 | +Since they work simultaneously, the minimum time needed is `max(2, 3, 1) = 3` seconds. |
| 32 | + |
| 33 | +**Example 2:** |
| 34 | + |
| 35 | +**Input:** mountainHeight = 10, workerTimes = [3,2,2,4] |
| 36 | + |
| 37 | +**Output:** 12 |
| 38 | + |
| 39 | +**Explanation:** |
| 40 | + |
| 41 | +* Worker 0 reduces the height by 2, taking `workerTimes[0] + workerTimes[0] * 2 = 9` seconds. |
| 42 | +* Worker 1 reduces the height by 3, taking `workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12` seconds. |
| 43 | +* Worker 2 reduces the height by 3, taking `workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12` seconds. |
| 44 | +* Worker 3 reduces the height by 2, taking `workerTimes[3] + workerTimes[3] * 2 = 12` seconds. |
| 45 | + |
| 46 | +The number of seconds needed is `max(9, 12, 12, 12) = 12` seconds. |
| 47 | + |
| 48 | +**Example 3:** |
| 49 | + |
| 50 | +**Input:** mountainHeight = 5, workerTimes = [1] |
| 51 | + |
| 52 | +**Output:** 15 |
| 53 | + |
| 54 | +**Explanation:** |
| 55 | + |
| 56 | +There is only one worker in this example, so the answer is `workerTimes[0] + workerTimes[0] * 2 + workerTimes[0] * 3 + workerTimes[0] * 4 + workerTimes[0] * 5 = 15`. |
| 57 | + |
| 58 | +**Constraints:** |
| 59 | + |
| 60 | +* <code>1 <= mountainHeight <= 10<sup>5</sup></code> |
| 61 | +* <code>1 <= workerTimes.length <= 10<sup>4</sup></code> |
| 62 | +* <code>1 <= workerTimes[i] <= 10<sup>6</sup></code> |
0 commit comments