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 ith 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 their engineers' speeds multiplied by the minimum efficiency among their engineers.

Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.

&nbsp;
Example 1:

Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2
Output: 60
Explanation: 
We have the maximum performance of the team by selecting engineer 2 (with speed=10 and efficiency=4) and engineer 5 (with speed=5 and efficiency=7). That is, performance = (10 + 5) * min(4, 7) = 60.


Example 2:

Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3
Output: 68
Explanation:
This is the same example as the first but k = 3. We can select engineer 1, engineer 2 and engineer 5 to get the maximum performance of the team. That is, performance = (2 + 10 + 5) * min(5, 4, 7) = 68.


Example 3:

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


&nbsp;
Constraints:


	1 &lt;= k &lt;= n &lt;= 105
	speed.length == n
	efficiency.length == n
	1 &lt;= speed[i] &lt;= 105
	1 &lt;= efficiency[i] &lt;= 108


class Solution:
    def maxPerformance(self, n: int, speed: List[int], efficiency: List[int], k: int) -> int:
        l = list(zip(efficiency,speed))
        l.sort(reverse=True)
        h = []
        res = 0
        mod = 1000000007
        mx_sum = 0
        print(l)
        for i in range(n):
            res = max(res , (mx_sum+l[i][1])*l[i][0])
            if len(h)<k-1:
                heappush(h,l[i][1])
                mx_sum+=l[i][1]
            elif k!=1:
                x=0
                if h:
                    x = heappop(h)
                heappush(h,max(x,l[i][1]))
                mx_sum = mx_sum - x + max(x,l[i][1])
        return res%mod
            
class Engineer {
    int speed, efficiency;
    Engineer(int speed, int efficiency) {
        this.speed = speed;
        this.efficiency = efficiency;
    }
}

class Solution {
    public int maxPerformance(int n, int[] speed, int[] efficiency, int k) {
        List<Engineer> engineers = new ArrayList<>();
        for(int i=0;i<n;i++) {
            engineers.add(new Engineer(speed[i], efficiency[i]));
        }
        engineers.sort((a, b) -> b.efficiency - a.efficiency);
        PriorityQueue<Engineer> maxHeap = new PriorityQueue<>((a,b) -> a.speed - b.speed);
        long maxPerformance = 0l, totalSpeed = 0l;
        for(Engineer engineer: engineers) {
            if(maxHeap.size() == k) {
                totalSpeed -= maxHeap.poll().speed;
            }
            totalSpeed += engineer.speed;
            maxHeap.offer(engineer);
            maxPerformance = Math.max(maxPerformance, totalSpeed * (long)engineer.efficiency);
        }
        return (int)(maxPerformance % 1_000_000_007);
    }
}
class Solution {
public:
    
    int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) {
        priority_queue<int, vector<int>, greater<int>> pq;
        long long sum = 0, ans = 0;
        const int m = 1e9 + 7;
        vector<vector<int>> pairs(n, vector<int> (2, 0));
        for(int i = 0; i < n; i++) pairs[i] = {efficiency[i], speed[i]};
        sort(pairs.rbegin(), pairs.rend());
        for(int i = 0; i < n; i++){
            sum += pairs[i][1];
            pq.push(pairs[i][1]);
            ans = max(ans,sum * pairs[i][0]);
            if(pq.size() >= k){
                sum -= pq.top();
                pq.pop();
            }
        }
        return ans%(m);
    }
}; 
var maxPerformance = function(n, speed, efficiency, k) {
    let ord = Array.from({length: n}, (_,i) => i)
    ord.sort((a,b) => efficiency[b] - efficiency[a])
    let sppq = new MinPriorityQueue(),
        totalSpeed = 0n, best = 0n
    for (let eng of ord) {
        sppq.enqueue(speed[eng])
        if (sppq.size() <= k) totalSpeed += BigInt(speed[eng])
        else totalSpeed += BigInt(speed[eng] - sppq.dequeue().element)
        let res = totalSpeed * BigInt(efficiency[eng])
        if (res > best) best = res
    }
    return best % 1000000007n
};
Maximum Performance of a Team