mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 02:41:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,60 +1,48 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>maxHeights</code> of <code>n</code> integers.</p>
|
||||
<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>
|
||||
|
||||
<p>You are tasked with building <code>n</code> towers in the coordinate line. The <code>i<sup>th</sup></code> tower is built at coordinate <code>i</code> and has a height of <code>heights[i]</code>.</p>
|
||||
|
||||
<p>A configuration of towers is <strong>beautiful</strong> if the following conditions hold:</p>
|
||||
|
||||
<ol>
|
||||
<li><code>1 <= heights[i] <= maxHeights[i]</code></li>
|
||||
<li><code>heights</code> is a <strong>mountain</strong> array.</li>
|
||||
</ol>
|
||||
|
||||
<p>Array <code>heights</code> is a <strong>mountain</strong> if there exists an index <code>i</code> such that:</p>
|
||||
|
||||
<ul>
|
||||
<li>For all <code>0 < j <= i</code>, <code>heights[j - 1] <= heights[j]</code></li>
|
||||
<li>For all <code>i <= k < n - 1</code>, <code>heights[k + 1] <= heights[k]</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>maximum possible sum of heights</strong> of a beautiful configuration of towers</em>.</p>
|
||||
<p>Return the <strong>maximum possible sum</strong> of heights of a mountain-shaped tower arrangement.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> maxHeights = [5,3,4,1,1]
|
||||
<strong>Output:</strong> 13
|
||||
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
|
||||
- 1 <= heights[i] <= maxHeights[i]
|
||||
- heights is a mountain of peak i = 0.
|
||||
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">heights = [5,3,4,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">13</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We remove some bricks to make <code>heights = [5,3,3,1,1]</code>, the peak is at index 0.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> maxHeights = [6,5,3,9,2,7]
|
||||
<strong>Output:</strong> 22
|
||||
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
|
||||
- 1 <= heights[i] <= maxHeights[i]
|
||||
- heights is a mountain of peak i = 3.
|
||||
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">heights = [6,5,3,9,2,7]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">22</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We remove some bricks to make <code>heights = [3,3,3,9,2,2]</code>, the peak is at index 3.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> maxHeights = [3,2,5,5,2,3]
|
||||
<strong>Output:</strong> 18
|
||||
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
|
||||
- 1 <= heights[i] <= maxHeights[i]
|
||||
- heights is a mountain of peak i = 2.
|
||||
Note that, for this configuration, i = 3 can also be considered a peak.
|
||||
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.
|
||||
</pre>
|
||||
<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>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == maxHeights <= 10<sup>3</sup></code></li>
|
||||
<li><code>1 <= maxHeights[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= n == heights.length <= 10<sup>3</sup></code></li>
|
||||
<li><code>1 <= heights[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user