PuTtA EaSY Solution C++ ✅ | Heap 🔥🔥 |
\n# Code\n\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        priority_queue<pair<int
\n# Code\n```\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        priority_queue<pair<int,int>> pq;\n        priority_queue<int> pq2;\n\n        for(int i=0;i<profits.size();i++){\n            pq.push({-1*capital[i],profits[i]});   \n        }\n\n        for(int i=0;i<k;i++){\n\n            while (!pq.empty() && -1*pq.top().first <= w )           {\n                pair<int,int> temp = pq.top();\n                pq.pop();\n                pq2.push(temp.second);\n            }\n                if(!pq2.empty()){\n                w += pq2.top();\n                pq2.pop();}\n                else break;\n            \n        }\n        return w;\n        \n    }\n};\n```
['Heap (Priority Queue)', 'C++']