Maximum Performance of a Team

Hard

Topics
ArrayGreedyHeapSorting

You are given k, and two arrays speed and efficiency of equal length describing engineers.

Choose at most k engineers. A team's performance is the sum of its speeds multiplied by the minimum efficiency among its members.

Return the maximum performance, modulo 10^9 + 7.

Example 1

Input:  k = 2, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2]
Output: 60
Explanation: Pick engineers 1 and 4: speeds 10 + 5 = 15, minimum efficiency 4, giving 60.

Example 2

Input:  k = 3, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2]
Output: 68

Constraints

  • 1 <= n <= 10^5
  • 1 <= k <= n
  • 1 <= speed[i] <= 10^5
  • 1 <= efficiency[i] <= 10^8
Run ⌘' · Submit ⌘⏎