Java | Priority Queue | 10 lines | O(n log n) time
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n*log(n))$$\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 {\n  public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n    var projects = new PriorityQueue<int[]>((a, b) -> Integer.compare(a[0], b[0]));\n\n    for (var i=0; i < profits.length; i++)\n      projects.offer(new int[] {capital[i], profits[i]});\n\n    var queue = new PriorityQueue<Integer>(Collections.reverseOrder());\n\n    while (k-- > 0) {\n      for (var a = projects.peek(); a != null && a[0] <= w; a = projects.peek())\n        queue.offer(projects.poll()[1]);\n\n      if (queue.isEmpty()) return w;\n      w += queue.poll();\n    }\n    return w;\n  }\n}\n```
['Heap (Priority Queue)', 'Java']