-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path826.cpp
More file actions
26 lines (24 loc) · 895 Bytes
/
826.cpp
File metadata and controls
26 lines (24 loc) · 895 Bytes
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
class Solution {
public:
int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {
int difficultyIdx = -1;
int workerIdx = 0;
int n = difficulty.size();
vector<pair<int, int>> diffAndProfit;
for (int i = 0; i < difficulty.size(); ++i) {
diffAndProfit.push_back({difficulty[i], profit[i]});
}
sort(diffAndProfit.begin(), diffAndProfit.end());
sort(worker.begin(), worker.end());
int maxProfit = 0;
int res = 0;
for (auto& workerCap : worker) {
while (difficultyIdx + 1 < n && diffAndProfit[difficultyIdx + 1].first <= workerCap) {
difficultyIdx++;
maxProfit = max(maxProfit, diffAndProfit[difficultyIdx].second);
}
res += maxProfit;
}
return res;
}
};