3301. Maximize the Total Height of Unique Towers Medium
1/**
2 * [3301] Maximize the Total Height of Unique Towers
3 *
4 * You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the i^th tower can be assigned.
5 * Your task is to assign a height to each tower so that:
6 * <ol>
7 * The height of the i^th tower is a positive integer and does not exceed maximumHeight[i].
8 * No two towers have the same height.
9 * </ol>
10 * Return the maximum possible total sum of the tower heights. If it's not possible to assign heights, return -1.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: maximumHeight<span class="example-io"> = [2,3,4,3]</span>
15 * Output: <span class="example-io">10</span>
16 * Explanation:
17 * We can assign heights in the following way: [1, 2, 4, 3].
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: maximumHeight<span class="example-io"> = [15,10]</span>
22 * Output: <span class="example-io">25</span>
23 * Explanation:
24 * We can assign heights in the following way: [15, 10].
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: maximumHeight<span class="example-io"> = [2,2,1]</span>
29 * Output: <span class="example-io">-1</span>
30 * Explanation:
31 * It's impossible to assign positive heights to each index so that no two towers have the same height.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= maximumHeight.length <= 10^5
37 * 1 <= maximumHeight[i] <= 10^9
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximize-the-total-height-of-unique-towers/
43// discuss: https://leetcode.com/problems/maximize-the-total-height-of-unique-towers/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn maximum_total_sum(maximum_height: Vec<i32>) -> i64 {
49
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3301() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.