C++(fastest) || Priority Queue
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n
\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\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        priority_queue<pair<int, int>> pq;\n        for(int i = 0; i < profit.size(); i++){\n            pq.push({profit[i], difficulty[i]});\n        }\n        int ans = 0;\n        sort(worker.begin(), worker.end());\n        int i = worker.size()-1;\n        while(!pq.empty() && i >= 0){\n            pair<int, int> p = pq.top();\n            if(worker[i] >= p.second){\n                ans += p.first;\n                i--;\n            }\n            else pq.pop();\n        }\n        return ans;\n    }\n};\n```
['Sorting', 'Heap (Priority Queue)', 'C++']