class Solution {
public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {
PriorityQueue<Integer[]> pq = new PriorityQueue<>((a, b)-> a[0] - b[0]);
PriorityQueue<Integer> pq2 = new PriorityQueue<>(Comparator.reverseOrder());
for(int i = 0; i < profits.length; i++) {
pq.add(new Integer[]{capital[i], profits[i]});
}
while(k-- != 0) {
while(!pq.isEmpty() && pq.peek()[0] <= w) {
pq2.add(pq.poll()[1]);
}
if(!pq2.isEmpty()) {
w += pq2.poll();
}
}
return w;
}
}
자바는 우선순위 큐 쓰기 쉽더라 C++ 보다..
poll 함수랑 람다가
C++ 우선순위 큐에 람다넣는건 너무 지저분해
댓글 0