From 913341174ec8b4450abe5727a370ada70ea55943 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Mon, 18 Aug 2025 21:55:08 +0900 Subject: [PATCH] 20250818 baekjoon --- code_study/Baekjoon/java/_7662.java | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 code_study/Baekjoon/java/_7662.java diff --git a/code_study/Baekjoon/java/_7662.java b/code_study/Baekjoon/java/_7662.java new file mode 100644 index 0000000..89cc2bf --- /dev/null +++ b/code_study/Baekjoon/java/_7662.java @@ -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 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(); + } +}