Kotlin Heap Solution
Intuition\nWe first sort the projects by their capital.\n\nWhen we finish the previous project, we check what new projects we can now participate, then we use a
# Intuition\nWe first sort the projects by their capital.\n\nWhen we finish the previous project, we check what new projects we can now participate, then we use a `PriorityQueue` to track the available projects that we can participate with.\n\nThe `PriorityQueue` will give us the most lucrative project.\n\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  fun findMaximizedCapital(k: Int, w: Int, profits: IntArray, capital: IntArray): Int {\n    val indices = (0 until profits.size).sortedWith(Comparator<Int>{a, b -> capital[b] - capital[a]}).toMutableList();\n    val pq = PriorityQueue<Int> { a, b -> b - a }\n    var res = w\n    repeat(k) {\n      while (!indices.isEmpty() && res >= capital[indices.last()])\n        pq.offer(profits[indices.removeAt(indices.size - 1)])\n      res += pq.poll() ?: 0\n    }\n    return res\n  }\n}\n```
['Kotlin']