Easy to understand , might help you
Intuition\nThe goal is to maximize the total profit by assigning each worker to a job that they can handle (i.e., a job whose difficulty is less than or equal t
# Intuition\nThe goal is to maximize the total profit by assigning each worker to a job that they can handle (i.e., a job whose difficulty is less than or equal to their ability), and that yields the highest profit.\n\n# Approach\n1. Sort the Workers: We start by sorting the worker array in descending order. This allows us to assign the hardest jobs (with the highest profit) to the most capable workers first.\n\n2. Pair Profits with Difficulties: We create a vector of pairs, c, where each pair consists of a profit and its corresponding difficulty. This step is necessary to keep track of which difficulty corresponds to which profit.\n\n3. Sort the Jobs by Profit: We then sort the vector c in descending order based on profit. This means that we will consider the highest paying jobs first.\n\n4. Assign Jobs to Workers: For each worker, starting from the most capable:\n\n    We iterate through the sorted list    of jobs.\n\n   We assign the first job that the worker can handle (i.e., a job whose difficulty is less than or equal to the worker\'s capability).\n\n   We add the profit from this job to the total profit and move to the next worker.\n\n# Complexity\n- Time complexity:\n    $$O(n*m)$$\n\n- Space complexity:\n   $$O(m)$$\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        reverse(worker.begin() , worker.end());\n        int totalprofit = 0 ;\n\n        vector<pair<int , int>> c ;\n        for(int i = 0 ; i < profit.size() ; i++){\n            pair p(profit[i] , difficulty[i]);\n            c.push_back(p);\n        }\n\n        sort(c.begin() , c.end());\n        reverse(c.begin() , c.end());\n\n        for(int i = 0 ; i < worker.size() ; i++){\n            int x = worker[i];\n            int  j = 0 ;\n            while(j < c.size()){\n                if(c[j].second <= x){\n                    totalprofit += c[j].first ;\n                    break;\n                }\n                j++;\n            }\n        }\n        return totalprofit ;\n    }\n\n};\n```
['C++']