Two approaches | Binary Search + Greedy Solution ✅
Here is the first approach using binary search\n\n\nclass Solution {\n    int getMaxProfit(vector<pair<int,int>> v,int diff){\n        int l=0,h=v.size()-1;\n  
Here is the first approach using binary search\n\n```\nclass Solution {\n    int getMaxProfit(vector<pair<int,int>> v,int diff){\n        int l=0,h=v.size()-1;\n        int profit = 0;\n        while(l<=h){\n            int mid = l + (h-l)/2;\n            if(v[mid].first <= diff){//if handling capacity for difficulty is greater it means current mid is a vaible option and we need to search for more difficult tasks\n                profit = v[mid].second;\n                l = mid + 1;\n            }else\n                h = mid - 1;\n        }\n        return profit;\n    }\npublic:\n    int maxProfitAssignment(vector<int>& d, vector<int>& p, vector<int>& w) {\n        vector<pair<int,int>> v;\n        for(int i=0;i<d.size();i++){\n            v.push_back({d[i],p[i]});\n        }\n        sort(v.begin(),v.end());\n        for(int i=1;i<v.size();i++){\n            v[i].second = max(v[i].second,v[i-1].second);\n        }\n        int ans = 0;\n        for(auto x:w){\n            ans += getMaxProfit(v,x);\n        }\n        return ans;\n    }\n};\n```\n\nHere is the greedy solution\n```\nclass Solution {\npublic:\n    int maxProfitAssignment(vector<int>& d, vector<int>& p, vector<int>& w) {\n        vector<pair<int,int>> v;\n        for(int i=0;i<d.size();i++){\n            v.push_back({d[i],p[i]});\n        }\n        sort(v.begin(),v.end());\n        sort(w.begin(),w.end());\n        int ans = 0,best=0,i=0;\n        for(auto x:w){\n            while(i<v.size() && x>=v[i].first){\n                best = max(best,v[i++].second);\n            }\n            ans += best;\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Greedy', 'C']