beats 100%
Intuition\n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n)  \n\n
# Intuition\n![Screenshot 2024-06-18 163451.png](https://assets.leetcode.com/users/images/7bdfebfa-feb8-4763-b1a8-50a2c644b878_1718708783.611542.png)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n   O(nlogn+mlogm)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code c++\n\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n        ios::sync_with_stdio(false);\n        cin.tie(nullptr);\n        cout.tie(nullptr);\n\n        vector<pair<int, int>> jobs;\n        for (int i = 0; i < difficulty.size(); ++i) {\n            jobs.emplace_back(difficulty[i], profit[i]);\n        }\n        sort(jobs.begin(), jobs.end());\n        sort(worker.begin(), worker.end());\n\n        int maxProfit = 0, i = 0, bestProfit = 0;\n        for (int w : worker) {\n            while (i < jobs.size() && jobs[i].first <= w) {\n                bestProfit = max(bestProfit, jobs[i].second);\n                ++i;\n            }\n            maxProfit += bestProfit;\n        }\n\n        return maxProfit;\n    }\n};\n// if you upvote this you will hear a good news in 10mins\n```\n# Code pthon3\n\n```\nclass Solution:\n    def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n        res, j, best, temp = 0, 0, 0, []\n        \n        for i in range(len(worker)):\n            temp.append((difficulty[i], profit[i]))\n        \n        temp.sort()\n        worker.sort()\n        \n        for work in worker:\n            while j < len(temp) and work >= temp[j][0]:\n                best = max(best, temp[j][1])\n                j += 1\n            \n            res += best\n        \n        return res\n# if you upvote this you will hear a good news in 10mins\n```\n\n
['C++', 'Python3']