Simple Priority Queue| East to understand and Intuitive|
Intuition\n Describe your first thoughts on how to solve this problem. \nIf we want to maximize the profit then we will try to assign the work having maximum pr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we want to maximize the profit then we will try to assign the work having maximum profit to maximum workers.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We use a priority queue to store the profits alongwith the difficulty level corresponding to the profit.\n2. Now we sort the worker array, so that we can start traversing from larget element i.e worker having the greatest ability.\n3. We keep popping from the heap if the difficulty level of the job is greater than the ability of the worker.\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(N) \n\n# Code\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n        priority_queue<pair<int,int>> pq;\n        \n        for(int i=0;i<profit.size();i++){\n            pq.push({profit[i],difficulty[i]});\n        }\n        sort(worker.begin(),worker.end());\n        int i=worker.size()-1;\n        int ans=0;\n        while(i>=0 && !pq.empty()){\n             if(worker[i]>=pq.top().second){\n                    ans+=pq.top().first;\n                    i--;\n             } \n             else{\n                 pq.pop();\n             }  \n        }\n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'C++']