1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/分隔数组以得到最大和 [partition-array-for-maximum-sum].html

37 lines
1.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>arr</code>,请你将该数组分隔为长度 <strong>最多 </strong>为 k 的一些(连续)子数组。分隔完成后,每个子数组的中的所有值都会变为该子数组中的最大值。</p>
<p>返回将数组分隔变换后能够得到的元素最大和。本题所用到的测试用例会确保答案是一个 32 位整数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [1,15,7,9,2,5,10], k = 3
<strong>输出:</strong>84
<strong>解释:</strong>数组变为 [15,15,15,9,10,10,10]</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4
<strong>输出:</strong>83
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [1], k = 1
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 500</code></li>
<li><code>0 &lt;= arr[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= k &lt;= arr.length</code></li>
</ul>