Easy to Understand | Beats 99%
Intuition\nUsing max heap for profits we can easily maximize our capital after k projects.\n\n# Approach\n- Create pairs of profits[i] and capital[i].`\n- Sort 
# Intuition\nUsing max heap for `profits` we can easily maximize our capital after k projects.\n\n# Approach\n- Create pairs of profits[i] and capital[i].`\n- Sort pairs by required capital.\n- MaxHeap: While iterating:\n1. Push profits of affordable projects into a max heap.\n2. Pop and add top profit to capital.\n- Repeat k times.\n\n# Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n```C++ []\n#define pi pair<int, int>\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n        int j = 0, n = profits.size();\n        vector<pi> temp;\n        priority_queue<int> maxHeap;\n\n        for(int i = 0; i < n; ++i) {\n            temp.push_back({capital[i], profits[i]});\n        }\n\n        sort(begin(temp), end(temp));\n        while(k--) {\n            while(j < n && w >= temp[j].first) {\n                maxHeap.push(temp[j++].second);\n            }\n\n            if(maxHeap.empty()) break;\n            w += maxHeap.top();\n            maxHeap.pop();\n        }\n\n        return w;\n    }\n};\n```\n```java []\nclass Solution {\n    class Pair {\n        int first;\n        int second;\n        \n        Pair(int first, int second) {\n            this.first = first;\n            this.second = second;\n        }\n    }\n    \n    public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n        int j = 0;\n        int n = profits.length;\n        List<Pair> temp = new ArrayList<>();\n        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());\n\n        for (int i = 0; i < n; ++i) {\n            temp.add(new Pair(capital[i], profits[i]));\n        }\n\n        Collections.sort(temp, Comparator.comparingInt(p -> p.first));\n        \n        while (k-- > 0) {\n            while (j < n && w >= temp.get(j).first) {\n                maxHeap.offer(temp.get(j++).second);\n            }\n\n            if (maxHeap.isEmpty()) break;\n            w += maxHeap.poll();\n        }\n\n        return w;\n    }\n}\n```\n```python []\nclass Solution:\n    def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n        n = len(profits)\n        temp = [(capital[i], profits[i]) for i in range(n)]\n        temp.sort()\n\n        maxHeap = []\n        j = 0\n\n        while k > 0:\n            while j < n and w >= temp[j][0]:\n                heapq.heappush(maxHeap, -temp[j][1])\n                j += 1\n            \n            if not maxHeap:\n                break\n            \n            w -= heapq.heappop(maxHeap)\n            k -= 1\n        \n        return w\n```\n```Go []\ntype Pair struct {\n\tfirst, second int\n}\n\ntype PairList []Pair\n\nfunc (p PairList) Len() int           { return len(p) }\nfunc (p PairList) Less(i, j int) bool { return p[i].first < p[j].first }\nfunc (p PairList) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }\n\ntype MaxHeap []int\n\nfunc (h MaxHeap) Len() int           { return len(h) }\nfunc (h MaxHeap) Less(i, j int) bool { return h[i] > h[j] }\nfunc (h MaxHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }\n\nfunc (h *MaxHeap) Push(x interface{}) {\n\t*h = append(*h, x.(int))\n}\n\nfunc (h *MaxHeap) Pop() interface{} {\n\told := *h\n\tn := len(old)\n\tx := old[n-1]\n\t*h = old[0 : n-1]\n\treturn x\n}\n\nfunc findMaximizedCapital(k int, w int, profits []int, capital []int) int {\n\tn := len(profits)\n\ttemp := make(PairList, n)\n\tmaxHeap := &MaxHeap{}\n\n\tfor i := 0; i < n; i++ {\n\t\ttemp[i] = Pair{capital[i], profits[i]}\n\t}\n\n\tsort.Sort(temp)\n\tj := 0\n\n\tfor k > 0 {\n\t\tfor j < n && w >= temp[j].first {\n\t\t\theap.Push(maxHeap, temp[j].second)\n\t\t\tj++\n\t\t}\n\n\t\tif maxHeap.Len() == 0 {\n\t\t\tbreak\n\t\t}\n\n\t\tw += heap.Pop(maxHeap).(int)\n\t\tk--\n\t}\n\n\treturn w\n}\n```\n\\\n
['C++', 'Java', 'Go', 'Python3', 'JavaScript']