Sorted list + max-heap
Time O(n log n + k log n) Space O(n)Sort indices by capital. Repeat k times: move every project with capital ≤ w into a max-heap of profits; if the heap is empty, stop; else add its top to w.
import java.util.*;
class Solution {
public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {
int n = profits.length;
Integer[] order = new Integer[n];
for (int i = 0; i < n; i++) order[i] = i;
Arrays.sort(order, Comparator.comparingInt(i -> capital[i]));
PriorityQueue<Integer> best = new PriorityQueue<>(Comparator.reverseOrder());
int next = 0;
while (k-- > 0) {
while (next < n && capital[order[next]] <= w) best.offer(profits[order[next++]]);
if (best.isEmpty()) break;
w += best.poll();
}
return w;
}
}Verdict: Each project enters the heap once.