Greedy, C++ Simple Approach ✅✅
if it Helps You, Please Upvote Me......!\n# Approach\n Describe your approach to solving the problem. \n\nApproach is simple, just try to understand the followi
# **if it Helps You, Please Upvote Me......!**\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nApproach is simple, just try to understand the following conditions:-\n\n**worker 5 can get all the jobs with difficulty 5,4,3,2,1  but in all of the Jobs worker will choose the job with Maximum Profit.**\n\nby using this approach we can easily solve this problem let\'s take an Example:-\n**Difficulty: [1,5,4] ,Profit: [5,3,7] ,  worker [4,6]**\n\n**for 1st worker(4):- this worker can get the job 1,4 but he will choose the job that has maximum profit( that is 7)**\n\n**for 2nd worker(6):- this worker can get all the job 1,4,5 but he will choose the job that has maximum profit( that is 7)**\n\n**in this way the answer will be 7+7 = 14**\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    \n   \n    int maxProfitAssignment(vector<int>& d, vector<int>& p, vector<int>& w) {\n\n        vector<int> pos(100005,0);\n    \n        for(int i = 0;i<d.size();i++)\n        pos[d[i]] = max(p[i],pos[d[i]]); \n        \n        int maxprofit = 0,ans = 0;\n        for(int i = 0;i<pos.size();i++)\n        {\n            maxprofit = max(maxprofit,pos[i]);\n            pos[i] = maxprofit;\n        }\n        for(int i = 0;i<w.size();i++)\n        ans+=pos[w[i]];\n\n        return ans;\n        \n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/2729c740-f688-4f96-980e-3cb24d75cdfa_1686205157.029114.jpeg)\n
['Greedy', 'Sorting', 'C++']