-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj7662.java
More file actions
54 lines (47 loc) · 1.73 KB
/
boj7662.java
File metadata and controls
54 lines (47 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class boj7662 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for (int i = 0; i < T; i++) {
int n = Integer.parseInt(br.readLine());
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int j = 0; j < n; j++) {
st = new StringTokenizer(br.readLine());
String str = st.nextToken();
if (str.equals("I")) {
int num = Integer.parseInt(st.nextToken());
map.put(num, map.getOrDefault(num, 0) + 1);
} else {
if (map.size() == 0) {
continue;
}
int type = Integer.parseInt(st.nextToken());
int num;
if (type == 1) {
num = map.lastKey();
} else {
num = map.firstKey();
}
if (map.put(num, map.get(num) - 1) == 1) {
map.remove(num);
}
}
}
if (map.size() == 0) {
sb.append("EMPTY\n");
} else {
sb.append(map.lastKey() + " " + map.firstKey() + "\n");
}
}
System.out.println(sb.toString());
}
}