-
Notifications
You must be signed in to change notification settings - Fork 0
/
18 June.cpp
31 lines (27 loc) · 846 Bytes
/
18 June.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {
sort(worker.begin() , worker.end());
reverse(worker.begin() , worker.end());
int totalprofit = 0 ;
vector<pair<int , int>> c ;
for(int i = 0 ; i < profit.size() ; i++){
pair p(profit[i] , difficulty[i]);
c.push_back(p);
}
sort(c.begin() , c.end());
reverse(c.begin() , c.end());
for(int i = 0 ; i < worker.size() ; i++){
int x = worker[i];
int j = 0 ;
while(j < c.size()){
if(c[j].second <= x){
totalprofit += c[j].first ;
break;
}
j++;
}
}
return totalprofit ;
}
};