Easy to understand c++ solution using priority_queue && sorting
Intuition\n Describe your first thoughts on how to solve this problem. \npush the elements in array in sorted order till it is less than current ans then pick t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\npush the elements in array in sorted order till it is less than current ans then pick the top elements till it does not become greater than top element\nbreak according to condition\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n# Complexity\n- Time complexity:(2*NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:(N+sizeof(pq))~(2*N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        \n        vector<pair<int,int>> vp;\n        int n=profits.size();\n\n        for(int i=0;i<n;i++)\n        {\n           \n            vp.push_back({capital[i],profits[i]});\n\n        }\n\n        sort(vp.begin(),vp.end());\n        int ans=w;\n        int i=0;\n        int m=vp.size();\n        priority_queue<int> pq;\n\n\n        while(i<m && k)\n        {\n\n           if(vp[i].first<=ans)\n           {\n             pq.push(vp[i].second);\n           }else\n           {\n               while(!pq.empty()&& k && vp[i].first>ans)\n               {\n                ans=ans+pq.top();\n                pq.pop();\n                k--;\n               }\n               if(!k || ans<vp[i].first)\n               {\n                break;\n               }\n               else \n               {\n                pq.push(vp[i].second);\n               }\n        \n           }\n           i++;\n\n        }\n\n        while(!pq.empty() && k)\n        {\n            ans=ans+pq.top();\n            pq.pop();\n            k--;\n\n        }\n      \n\n        return ans;\n    }\n};\n```
['C++']