class Solution { public: #define LL long long int maxPerformance(int n, vector<int>& speed, vector<int>& efficiency, int k) { vector<pair<int,int>> spef; for(int i=0;i<n;i++){ spef.push_back({efficiency[i],speed[i]}); } sort(spef.begin(), spef.end()); LL res=0; LL sum=0; priority_queue<int, vector<int>, greater<int>> pq; for(int i=n-1;i>=0;i--){ sum+=spef[i].second; pq.push(spef[i].second); if(pq.size()>k){ sum-=pq.top(); pq.pop(); } res=max(res,sum*spef[i].first); } int mod=1E9+7; return (int)(res%mod); } };