3296. Minimum Number of Seconds to Make Mountain Height Zero Medium
1/**
2 * [3296] Minimum Number of Seconds to Make Mountain Height Zero
3 *
4 * You are given an integer mountainHeight denoting the height of a mountain.
5 * You are also given an integer array workerTimes representing the work time of workers in seconds.
6 * The workers work simultaneously to reduce the height of the mountain. For worker i:
7 *
8 * To decrease the mountain's height by x, it takes workerTimes[i] + workerTimes[i] * 2 + ... + workerTimes[i] * x seconds. For example:
9 *
10 * To reduce the height of the mountain by 1, it takes workerTimes[i] seconds.
11 * To reduce the height of the mountain by 2, it takes workerTimes[i] + workerTimes[i] * 2 seconds, and so on.
12 *
13 *
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 * <strong class="example">Example 1:
18 * <div class="example-block">
19 * Input: <span class="example-io">mountainHeight = 4, workerTimes = [2,1,1]</span>
20 * Output: <span class="example-io">3</span>
21 * Explanation:
22 * One way the height of the mountain can be reduced to 0 is:
23 *
24 * Worker 0 reduces the height by 1, taking workerTimes[0] = 2 seconds.
25 * Worker 1 reduces the height by 2, taking workerTimes[1] + workerTimes[1] * 2 = 3 seconds.
26 * Worker 2 reduces the height by 1, taking workerTimes[2] = 1 second.
27 *
28 * Since they work simultaneously, the minimum time needed is max(2, 3, 1) = 3 seconds.
29 * </div>
30 * <strong class="example">Example 2:
31 * <div class="example-block">
32 * Input: <span class="example-io">mountainHeight = 10, workerTimes = [3,2,2,4]</span>
33 * Output: <span class="example-io">12</span>
34 * Explanation:
35 *
36 * Worker 0 reduces the height by 2, taking workerTimes[0] + workerTimes[0] * 2 = 9 seconds.
37 * Worker 1 reduces the height by 3, taking workerTimes[1] + workerTimes[1] * 2 + workerTimes[1] * 3 = 12 seconds.
38 * Worker 2 reduces the height by 3, taking workerTimes[2] + workerTimes[2] * 2 + workerTimes[2] * 3 = 12 seconds.
39 * Worker 3 reduces the height by 2, taking workerTimes[3] + workerTimes[3] * 2 = 12 seconds.
40 *
41 * The number of seconds needed is max(9, 12, 12, 12) = 12 seconds.
42 * </div>
43 * <strong class="example">Example 3:
44 * <div class="example-block">
45 * Input: <span class="example-io">mountainHeight = 5, workerTimes = [1]</span>
46 * Output: <span class="example-io">15</span>
47 * Explanation:
48 * 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.
49 * </div>
50 *
51 * Constraints:
52 *
53 * 1 <= mountainHeight <= 10^5
54 * 1 <= workerTimes.length <= 10^4
55 * 1 <= workerTimes[i] <= 10^6
56 *
57 */
58pub struct Solution {}
59
60// problem: https://leetcode.com/problems/minimum-number-of-seconds-to-make-mountain-height-zero/
61// discuss: https://leetcode.com/problems/minimum-number-of-seconds-to-make-mountain-height-zero/discuss/?currentPage=1&orderBy=most_votes&query=
62
63// submission codes start here
64
65impl Solution {
66 pub fn min_number_of_seconds(mountain_height: i32, worker_times: Vec<i32>) -> i64 {
67
68 }
69}
70
71// submission codes end
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_3296() {
79 }
80}
81
Back
© 2025 bowen.ge All Rights Reserved.