From 3d92747d56428012077327cf518dde8450a4fd4b Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Wed, 30 Jul 2025 23:51:36 +0900 Subject: [PATCH] =?UTF-8?q?[20250730]=20BOJ=20/=20G4=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=91=20=EC=9A=B0=EC=84=A0=EC=88=9C=EC=9C=84=20=ED=81=90=20?= =?UTF-8?q?/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\210\234\354\234\204 \355\201\220.md" | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 "LiiNi-coder/202507/30 BOJ \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" diff --git "a/LiiNi-coder/202507/30 BOJ \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" "b/LiiNi-coder/202507/30 BOJ \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" new file mode 100644 index 00000000..03bac806 --- /dev/null +++ "b/LiiNi-coder/202507/30 BOJ \354\235\264\354\244\221 \354\232\260\354\204\240\354\210\234\354\234\204 \355\201\220.md" @@ -0,0 +1,43 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; +import java.util.TreeMap; + +public class Main { + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + + for(int t = 0; t map = new TreeMap<>(); + + for (int i = 0; i < K; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + String command = st.nextToken(); + int value = Integer.parseInt(st.nextToken()); + + if (command.equals("I")) { + map.put(value, map.getOrDefault(value, 0) + 1); + } else if (command.equals("D")) { + if (map.isEmpty()) + continue; + int key = (value == 1) ? map.lastKey() : map.firstKey(); + 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()); + } + } + } +} +```