2025-08-18 21:55:08 +09:00

45 lines
1.3 KiB
Java

import java.util.*;
public class _7662 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for (int t = 0; t < T; t++) {
TreeMap<Integer, Integer> map = new TreeMap<>();
int K = Integer.parseInt(sc.nextLine());
for (int k = 0; k < K; k++) {
String[] line = sc.nextLine().split(" ");
char order = line[0].charAt(0);
int n = Integer.parseInt(line[1]);
if (order == 'I') {
map.put(n, map.getOrDefault(n, 0) + 1);
} else {
if (map.isEmpty()) {
continue;
}
int key = (n == -1) ? map.firstKey() : map.lastKey();
int count = map.get(key);
if (count == 1) {
map.remove(key);
}
else {
map.put(key, count - 1);
}
}
}
if (map.isEmpty()) {
System.out.println("EMPTY");
} else {
System.out.println(map.lastKey() + " " + map.firstKey());
}
}
sc.close();
}
}