826. 安排工作以达到最大收益
题目链接:826. 安排工作以达到最大收益
代码如下:
class Solution
{
public:int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {vector<pair<int,int>> jobs;for(int i=0;i<profit.size();i++){jobs.emplace_back(difficulty[i],profit[i]);}sort(jobs.begin(),jobs.end());sort(worker.begin(),worker.end());int j=0,res=0,best=0;for(int i=0;i<worker.size();i++){while(j<jobs.size()&&worker[i]>=jobs[j].first){best=max(best,jobs[j].second);j++;}res+=best;}return res;}
};