Maximum Performance of a Team
Real-world version: Rating a Group of TurbinesThe statement here is our own: the same inputs, outputs and technique.
A wind farm owns n turbines. Turbine i produces output[i] units of power and runs at a steadiness of steadiness[i].
A group is any non-empty selection of at most k turbines. Its rating is the total output of the turbines in it multiplied by the smallest steadiness among them.
Return the largest rating a group can reach. Because that number can be large, return it modulo 10^9 + 7.
Examples
Example 1
- Input
- n = 3, output = [2, 4, 6], steadiness = [8, 5, 3], k = 2
- Output
- 30
The first two turbines total 6 in output with a smallest steadiness of 5, a rating of 30. The last two total 10 with a smallest steadiness of 3, also 30. Nothing does better.
Example 2
- Input
- n = 2, output = [10, 1], steadiness = [10, 1], k = 2
- Output
- 100
Adding the second turbine lifts the output to 11 but drags the smallest steadiness down to 1, rating 11. The first turbine on its own rates 100, so the best group is smaller than the limit allows.
Example 3
- Input
- n = 2, output = [10, 1], steadiness = [1, 100], k = 1
- Output
- 100
Only one turbine may be taken. The first rates 10 and the second rates 100.
Constraints
- 1 <= k <= n <= 10^5
- output.length == n
- steadiness.length == n
- 1 <= output[i] <= 10^5
- 1 <= steadiness[i] <= 10^8
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_performance(n: int, output: list[int], steadiness: list[int], k: int) -> int:public int maxPerformance(int n, int[] output, int[] steadiness, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 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
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy
- Meeting Rooms IIReal-world version: Peak Charging Bay DemandMedium
- Task SchedulerReal-world version: Press Die CooldownMedium
- Maximum Number of Events That Can Be AttendedReal-world version: Most Inspections BookedMedium