Skip to content

Commit 1f8d0e9

Browse files
authored
Create 826. Most Profit Assigning Work
1 parent be3b762 commit 1f8d0e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

826. Most Profit Assigning Work

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public:
3+
int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {
4+
int n = worker.size();
5+
sort(worker.begin(),worker.end());
6+
vector<pair<int,int>> nums(n);
7+
8+
for(int i=0;i<n;i++)
9+
{
10+
nums[i] = {difficulty[i],profit[i]};
11+
}
12+
sort(nums.begin(),nums.end());
13+
14+
int maxProfit = 0;
15+
int tempProfit = 0;
16+
for(int i=0,j=0;i<n;i++)
17+
{
18+
while(j<n && nums[j].first <= worker[i])
19+
{
20+
tempProfit = max(nums[j].second,tempProfit);
21+
j++;
22+
}
23+
if(j>0 && nums[j-1].first <= worker[i])
24+
{
25+
maxProfit = maxProfit + tempProfit;
26+
}
27+
}
28+
return maxProfit;
29+
}
30+
};

0 commit comments

Comments
 (0)