Skip to content

Commit d78f340

Browse files
authored
Merge pull request #579 from AlgorithmWithGod/LiiNi-coder
[20250730] BOJ / G4 / 이중 우선순위 큐 / 이인희
2 parents d5c49aa + 3d92747 commit d78f340

File tree

1 file changed

+43
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)