Skip to content

Commit be97390

Browse files
authored
[20251130] BOJ / G5 / 이중 우선순위 큐 / 이준희
1 parent c708154 commit be97390

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st;
9+
int T = Integer.parseInt(br.readLine());
10+
11+
for (int t = 0; t < T; t++) {
12+
int K = Integer.parseInt(br.readLine());
13+
TreeMap<Integer, Integer> map = new TreeMap<>();
14+
15+
for (int i = 0; i < K; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
char op = st.nextToken().charAt(0);
18+
int num = Integer.parseInt(st.nextToken());
19+
20+
if (op == 'I') {
21+
map.put(num, map.getOrDefault(num, 0) + 1);
22+
}
23+
else {
24+
if (map.isEmpty()) {
25+
continue;
26+
}
27+
28+
int key;
29+
30+
if (num == 1) {
31+
key = map.lastKey();
32+
}
33+
else {
34+
key = map.firstKey();
35+
}
36+
37+
int cnt = map.get(key);
38+
if (cnt == 1) {
39+
map.remove(key);
40+
} else {
41+
map.put(key, cnt - 1);
42+
}
43+
}
44+
}
45+
46+
if (map.isEmpty()) {
47+
System.out.println("EMPTY");
48+
} else {
49+
int max = map.lastKey();
50+
int min = map.firstKey();
51+
System.out.println(max + " " + min);
52+
}
53+
}
54+
}
55+
}
56+
```

0 commit comments

Comments
 (0)