mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
54 lines
2.5 KiB
HTML
54 lines
2.5 KiB
HTML
<p>You are given a <strong>0-indexed</strong> integer array <code>stations</code> of length <code>n</code>, where <code>stations[i]</code> represents the number of power stations in the <code>i<sup>th</sup></code> city.</p>
|
|
|
|
<p>Each power station can provide power to every city in a fixed <strong>range</strong>. In other words, if the range is denoted by <code>r</code>, then a power station at city <code>i</code> can provide power to all cities <code>j</code> such that <code>|i - j| <= r</code> and <code>0 <= i, j <= n - 1</code>.</p>
|
|
|
|
<ul>
|
|
<li>Note that <code>|x|</code> denotes <strong>absolute</strong> value. For example, <code>|7 - 5| = 2</code> and <code>|3 - 10| = 7</code>.</li>
|
|
</ul>
|
|
|
|
<p>The <strong>power</strong> of a city is the total number of power stations it is being provided power from.</p>
|
|
|
|
<p>The government has sanctioned building <code>k</code> more power stations, each of which can be built in any city, and have the same range as the pre-existing ones.</p>
|
|
|
|
<p>Given the two integers <code>r</code> and <code>k</code>, return <em>the <strong>maximum possible minimum power</strong> of a city, if the additional power stations are built optimally.</em></p>
|
|
|
|
<p><strong>Note</strong> that you can build the <code>k</code> power stations in multiple cities.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> stations = [1,2,4,5,0], r = 1, k = 2
|
|
<strong>Output:</strong> 5
|
|
<strong>Explanation:</strong>
|
|
One of the optimal ways is to install both the power stations at city 1.
|
|
So stations will become [1,4,4,5,0].
|
|
- City 0 is provided by 1 + 4 = 5 power stations.
|
|
- City 1 is provided by 1 + 4 + 4 = 9 power stations.
|
|
- City 2 is provided by 4 + 4 + 5 = 13 power stations.
|
|
- City 3 is provided by 5 + 4 = 9 power stations.
|
|
- City 4 is provided by 5 + 0 = 5 power stations.
|
|
So the minimum power of a city is 5.
|
|
Since it is not possible to obtain a larger power, we return 5.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> stations = [4,4,4,4], r = 0, k = 3
|
|
<strong>Output:</strong> 4
|
|
<strong>Explanation:</strong>
|
|
It can be proved that we cannot make the minimum power of a city greater than 4.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>n == stations.length</code></li>
|
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
|
<li><code>0 <= stations[i] <= 10<sup>5</sup></code></li>
|
|
<li><code>0 <= r <= n - 1</code></li>
|
|
<li><code>0 <= k <= 10<sup>9</sup></code></li>
|
|
</ul>
|