LC 1383. Maximum Performance of a Team

link

LC 1383. Maximum Performance of a Team

 

 

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);
    }
};

 

上一篇:Tom&Jerry_team——团队展示


下一篇:小团队Git协作管理