Easiest answer using Sorting and Two Pointers.
Intuition\nIn this question we have to calculate the maximum profit that worker can earn so the intuition to do this question is to somehow sort the profit arra
# Intuition\nIn this question we have to calculate the maximum profit that worker can earn so the intuition to do this question is to somehow sort the profit array in decending order keeping the difficulty array in order with profit array then using two pointer we can traverse in worker and diffulty array and checking if that particular worker can do that difficuty task or not.if that worker can do that question then we can store the profit for that worker.\n\n# Approach\n1. Create the vector of pairs such that its first element is profit and second element is difficulty.\n2. sort the new array and worker array in decending order.\n3. Create a variable "ans" which will keep the track of profit.\n4. Now using two pointer traverse on new array and worker array and check if that particular worker can do that task or not if that worker can do the task add the profit in the ans and move to next worker and if the worker cannot do the task move to next element in new array.\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n        vector<pair<int,int>>arr;\n        for(int i=0;i<difficulty.size();i++) {\n            arr.push_back(make_pair(profit[i],difficulty[i]));\n        }\n        sort(arr.begin(),arr.end(),greater<pair<int,int>>());\n        sort(worker.begin(),worker.end(),greater<int>());\n        int i=0,j=0;\n        int ans = 0;\n        while(i<arr.size() and j<worker.size()) {\n            if(worker[j] >= arr[i].second) {\n                ans+=arr[i].first;\n                j++;\n            } else {\n                i++;\n            }\n        }\n        return ans;\n    }\n};\n```
['Two Pointers', 'Sorting', 'C++']