Easy Solution for beginners || sorting || Two pointer approach
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind solving the problem of maximizing profit by assigning jobs to work
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind solving the problem of maximizing profit by assigning jobs to workers based on their abilities lies in leveraging sorting and efficient matching. By sorting the workers by their abilities and the jobs by their difficulty, we can streamline the process of finding the most profitable job that each worker can handle. Using a two-pointer technique, we efficiently traverse both lists, updating the highest available profit for each worker\'s capability as we go. This ensures that we always assign the best possible job to each worker without redundant checks, thus maximizing the total profit in an optimal and efficient manner.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach to maximizing profit by assigning jobs to workers involves sorting and efficient matching. First, sort the worker array by their abilities and create a vector of job pairs (difficulty and profit), sorting it by difficulty. Then, use a two-pointer technique to iterate through the sorted worker and jobs arrays. For each worker, update the maximum profit achievable up to their ability by checking jobs in increasing order of difficulty. Track the highest profit found so far and accumulate this for each worker, ensuring each one gets the most profitable job they can handle. Finally, return the accumulated maximum profit. This method ensures optimal and efficient assignment of jobs to workers.\n\n\n\n\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(NlogN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n        sort(worker.begin(),worker.end());\n        vector<pair<int,int>>v;\n        for(int i=0;i<difficulty.size();i++){\n            v.push_back({difficulty[i],profit[i]});\n        }\n        sort(v.begin(),v.end());\n        int maxi=0;\n        int bonus=0;\n        int i=0;\n        for(auto it : worker){\n            while(i<v.size() && v[i].first<=it){\n                bonus=max(bonus,v[i].second);\n                i++;\n            }\n            maxi+=bonus;\n        }\n        return maxi;\n    }\n};\n```
['Sorting', 'C++']