20250818 baekjoon
This commit is contained in:
parent
bad8a6f6ff
commit
913341174e
44
code_study/Baekjoon/java/_7662.java
Normal file
44
code_study/Baekjoon/java/_7662.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user