Skip to content

Commit 53384c8

Browse files
authored
[20250929] PGM / LV2 / 디펜스 게임 / 김수연
1 parent ab5a675 commit 53384c8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(int n, int k, int[] enemy) {
5+
int answer = enemy.length;
6+
PriorityQueue<Integer> pq = new PriorityQueue<>();
7+
8+
for (int i = 0; i < enemy.length; i++) {
9+
pq.offer(enemy[i]);
10+
11+
if(pq.size() > k) n -= pq.poll();
12+
13+
if (n < 0) return i;
14+
}
15+
return answer;
16+
}
17+
}
18+
```

0 commit comments

Comments
 (0)