Maximize the Minimum Powered City
Real-world version: Lift the Weakest Relay StopThe statement here is our own: the same inputs, outputs and technique.
A single road has n numbered stops. stations[i] is how many relay masts stand at stop i. A mast standing at stop j puts signal on every stop i with |i - j| <= r, so the signal at stop i is the number of masts standing at stops within r of it, counting every mast at every such stop.
You may erect k further masts. Each one has to stand at one of the n stops, several new masts may share a stop, and they may share a stop with existing masts. You do not have to erect all k.
Return the largest value the weakest stop's signal can be raised to, that is the largest possible value of the smallest signal over all n stops.
Examples
Example 1
- Input
- stations = [1, 2, 4, 5, 0], r = 1, k = 2
- Output
- 5
The starting signals are 3, 7, 11, 9 and 5. Erecting both new masts at stop 1 gives the stop counts [1, 4, 4, 5, 0] and signals 5, 9, 13, 9 and 5, so the weakest stop reads 5.
Example 2
- Input
- stations = [0, 0, 0], r = 1, k = 1
- Output
- 1
A single mast at stop 1 reaches stops 0, 1 and 2, so every stop reads 1.
Example 3
- Input
- stations = [4, 4, 4, 4], r = 0, k = 0
- Output
- 4
With a reach of 0 each stop only sees its own masts, and no new mast may be erected, so the weakest signal stays at 4.
Constraints
- n == stations.length
- 1 <= n <= 10^5
- 0 <= stations[i] <= 10^5
- 0 <= r <= n - 1
- 0 <= k <= 10^9
- The answer never exceeds 1.1 * 10^10.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_power(stations: list[int], r: int, k: int) -> int:public long maxPower(int[] stations, int r, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Frequency of the Most Frequent ElementReal-world version: Plates at One ThicknessMedium
- Maximum Coins From K Consecutive BagsReal-world version: Richest Run of Consecutive BinsMedium
- Shortest Subarray with Sum at Least KReal-world version: Shortest Run Meeting the Grid QuotaHard
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy