Maximum Performance of a Team - Problem
You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n.
speed[i] and efficiency[i] represent the speed and efficiency of the i-th engineer respectively.
Choose at most k different engineers out of the n engineers to form a team with the maximum performance.
The performance of a team is the sum of its engineers' speeds multiplied by the minimum efficiency among its engineers.
Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.
Input & Output
Example 1 — Basic Case
$
Input:
n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2
›
Output:
60
💡 Note:
We choose engineers 2 and 5 (0-indexed) with speeds [10,5] and efficiencies [4,7]. Performance = (10+5) × min(4,7) = 15 × 4 = 60.
Example 2 — Single Engineer
$
Input:
n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3
›
Output:
68
💡 Note:
Choose engineer with efficiency 9 and speed 1, plus top 2 others by speed considering efficiency constraint. Best combination gives performance 68.
Example 3 — All Engineers
$
Input:
n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 6
›
Output:
72
💡 Note:
When k equals n, we can consider all engineers. The optimal team maximizes sum of speeds × minimum efficiency across all possible combinations.
Constraints
- 1 ≤ n ≤ 105
- 1 ≤ speed[i] ≤ 105
- 1 ≤ efficiency[i] ≤ 108
- 1 ≤ k ≤ n
Visualization
Tap to expand
Understanding the Visualization
1
Input
Engineers with speed and efficiency values, team size k
2
Process
Find optimal team that maximizes sum of speeds × minimum efficiency
3
Output
Maximum performance value modulo 10^9 + 7
Key Takeaway
🎯 Key Insight: Sort by efficiency descending, then greedily pick top k speeds using a min-heap to try every possible minimum efficiency
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code