Intuitive CPP Solution using Priority Queue
Intuition\n Describe your first thoughts on how to solve this problem. \nQuestion - Eack worker can do maximum one work and eack work can be done any number of 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Question** - Eack worker can do maximum one work and eack work can be done any number of times. We need to maximize the total profit \n**Constraint**:\nA worker j can do a particular i work only if\n **worker[j]>=difficulty[i]**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst we need to find how many works a worker is eligible to perform and among these we need to assign the work with the maximum profit.\n\nLet difficulty array: [2,4,6,8,10]\nprofit array:[10,20,30,40,50]\nworker array:[4,5,6,7]\n\nFirst Lets sort the difficulty array so that  if worker[0] can not perform difficulty[2] task it cannot perform rest of the tasks\n\nBut each difficulty[i] has a particular profit[i] so it\'s better to make a pair of vector i.e. vector<pair<difficulty,profit>>data\n\nTherefore vector<pair<int,int>>data=[{2,10},{4,20},{6,30},{8,40},{10,50}];\nNow sort this data array according to difficulty\nsort(data.begin(),data.end());\n\nWe should also sort the worker array because if a worker[0] can perform a particular task all others also can..\nsort(worker.begin(),worker.end());\n\nNow Let say worker[i] is eligible to perform difficulty[j] , difficulty[j+1] , difficulty[j+2] work we need to select the max profit among all these.\n\nFor this we can maintain a **max heap** which will hold the profits which a particular worker can perform and the max profit will be on the top of the heap.\npriority queue prof\n\nNow we will iterate through all workers and for each worker if that worker can perform a task we will push its profit to priority_queue  and will move to the next task and if it cannot perform the task we will simply take the maximum profit using **prof.top()**\nand we will move to the next worker.\n\n**Note:** No need to remove elements form the priority queue because a task can be taken any number of times and since the workers are sorted so if a worker can perform a particular task , all other also can.. So the priority queue will always hold the tasks which can be performed by a particular worker.\n\n**If you understand the solution please upvote**\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$max(nlogn , mlog m)$$\n\n- Space complexity:\n<!-- Add your space 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        int n=difficulty.size();\n        int m=worker.size();\n         int cnt=0;\n        vector<pair<int,int>>data;\n\n        for(int i=0;i<n;i++)\n        data.push_back({difficulty[i],profit[i]});\n\n        sort(data.begin(),data.end());\n        priority_queue<int>pq;\n\n        sort(worker.begin(),worker.end());\n        int j=0;\n        for(int i=0;i<m;i++)\n        {\n            while(j<n && worker[i]>=data[j].first)\n            {\n                pq.push(data[j].second);\n                j++;\n            }\n            if(!pq.empty())\n            cnt+=pq.top();\n        }\n        return cnt;\n    }\n};\n```
['C++']