2025-01-09 20:29:41 +08:00
< p > You are given an array < code > heights< / code > of < code > n< / code > integers representing the number of bricks in < code > n< / code > consecutive towers. Your task is to remove some bricks to form a < strong > mountain-shaped< / strong > tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.< / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > Return the < strong > maximum possible sum< / strong > of heights of a mountain-shaped tower arrangement.< / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > < / p >
< p > < strong class = "example" > Example 1:< / strong > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< div class = "example-block" >
< p > < strong > Input:< / strong > < span class = "example-io" > heights = [5,3,4,1,1]< / span > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong > Output:< / strong > < span class = "example-io" > 13< / span > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong > Explanation:< / strong > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > We remove some bricks to make < code > heights = [5,3,3,1,1]< / code > , the peak is at index 0.< / p >
< / div >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< div class = "example-block" >
< p > < strong > Input:< / strong > < span class = "example-io" > heights = [6,5,3,9,2,7]< / span > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong > Output:< / strong > < span class = "example-io" > 22< / span > < / p >
< p > < strong > Explanation:< / strong > < / p >
2023-09-24 19:54:57 +08:00
2025-01-09 20:29:41 +08:00
< p > We remove some bricks to make < code > heights = [3,3,3,9,2,2]< / code > , the peak is at index 3.< / p >
< / div >
2023-09-24 19:54:57 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2025-01-09 20:29:41 +08:00
< div class = "example-block" >
< p > < strong > Input:< / strong > < span class = "example-io" > heights = [3,2,5,5,2,3]< / span > < / p >
< p > < strong > Output:< / strong > < span class = "example-io" > 18< / span > < / p >
< p > < strong > Explanation:< / strong > < / p >
< p > We remove some bricks to make < code > heights = [2,2,5,5,2,2]< / code > , the peak is at index 2 or 3.< / p >
< / div >
2023-09-24 19:54:57 +08:00
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
2025-01-09 20:29:41 +08:00
< li > < code > 1 < = n == heights.length < = 10< sup > 3< / sup > < / code > < / li >
< li > < code > 1 < = heights[i] < = 10< sup > 9< / sup > < / code > < / li >
2023-09-24 19:54:57 +08:00
< / ul >