Easy c++ sorting solution beats 100%
Intuition\n# Sorting and Greedy approach to select maximum profit job (\u25CF\'\u25E1\'\u25CF)\n\n# Approach\n### To jump on approach first we have to think wha
# Intuition\n# Sorting and Greedy approach to select maximum profit job (\u25CF\'\u25E1\'\u25CF)\n\n# Approach\n### To jump on approach first we have to think what Question is trying to say \n### there are three vectors \n1. **difficulty** which tells about works difficulty. \n2. **profit** which tells the profit of a work.\n3. **worker** which tells the potential of a worker.\n\nso worker can only do that job whose difficulty is less then or equal to there potential and at same time worker have to select that job which give more profit as well \n \nmain work is to sort difficulty and profit(w.r.t to difficulty after sort) then use a pointer which traverse through worker and use a pointer who go to check if difficulty is less then or equal to workers potential or not if yes then it will check the profit because we also have to maximize the profit as well\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n $$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n        int n = difficulty.size();\n        vector<pair<int, int>> job(n);\n        for (int i = 0; i < n; ++i) {\n            job[i] = {difficulty[i], profit[i]};\n        }\n        sort(job.begin(), job.end());\n        sort(worker.begin(), worker.end());\n        \n        int maxprofit = 0;\n        int jobindex = 0;\n        int val= 0;\n        int totalprofit = 0;\n        // int m=worker.size();\n        for(int ele: worker)\n        {\n            while(jobindex<n && ele>=job[jobindex].first)\n            {\n                val=max(val,job[jobindex].second);\n                jobindex++;\n            }\n            totalprofit+=val;\n        }\n        \n       return totalprofit;\n    }\n};\n```\n![72ueap.webp](https://assets.leetcode.com/users/images/ece50b9e-9045-406d-aff2-f476b13db5f8_1718810686.8821235.webp)\n
['Sorting', 'C++']