Easy to understand C++ Solution beats 90%
Intuition\n Describe your first thoughts on how to solve this problem. \nWhenver we see first k or last k elements based on some order, then more probably than 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhenver we see first k or last k elements based on some order, then more probably than not, it is a problem related to priority queues.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe first create a pair vector of profits and capital, then we sort the vector based on the capital, that is the capital required should be less than or equal to the current capital, since we only want to compare with the capital. Now once we have the array sorted, we insert the profit values for which capital value is less than or equal to current w(capital). Then we pick the top element from the priority queue, then we update w by adding profit value and repeat the current process until either k==0 or priority queue is empty. Finally, we get the desired k value, which we return.\n# Complexity\n- Time complexity:O(nlogn)\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 findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        vector<pair<int,int>> vec;\n        for(int i=0; i<profits.size(); i++){\n            vec.push_back({profits[i],capital[i]});\n        }\n        auto comp = [](pair<int,int> a, pair<int,int> b){\n            return a.second < b.second;\n        };\n        sort(vec.begin(),vec.end(),comp);\n        priority_queue<int> pq;\n        int j=0;\n        while(j<profits.size() && vec[j].second <= w){\n            pq.push(vec[j].first);\n            j++;\n        }\n        while(!pq.empty() && k > 0){\n            w += pq.top();\n            pq.pop();\n            while(j<profits.size() && vec[j].second <= w){\n                pq.push(vec[j].first);\n                j++;\n            }\n            k--;\n        }\n        return w;\n    }\n};\n```\n\n# Please upvote if the solution helped you!
['C++']