From ed9f944f909758d42b38876045187817a0d05d65 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:56:27 +0900 Subject: [PATCH] =?UTF-8?q?[20250813]=20BOJ=20/=20G2=20/=20=EA=B0=80?= =?UTF-8?q?=EC=9A=B4=EB=8D=B0=EB=A5=BC=20=EB=A7=90=ED=95=B4=EC=9A=94=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\247\220\355\225\264\354\232\224.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "JHLEE325/202508/13 BOJ G2 \352\260\200\354\232\264\353\215\260\353\245\274 \353\247\220\355\225\264\354\232\224.md" diff --git "a/JHLEE325/202508/13 BOJ G2 \352\260\200\354\232\264\353\215\260\353\245\274 \353\247\220\355\225\264\354\232\224.md" "b/JHLEE325/202508/13 BOJ G2 \352\260\200\354\232\264\353\215\260\353\245\274 \353\247\220\355\225\264\354\232\224.md" new file mode 100644 index 00000000..d90e1407 --- /dev/null +++ "b/JHLEE325/202508/13 BOJ G2 \352\260\200\354\232\264\353\215\260\353\245\274 \353\247\220\355\225\264\354\232\224.md" @@ -0,0 +1,40 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + StringBuilder sb = new StringBuilder(); + + int N = Integer.parseInt(br.readLine().trim()); + + PriorityQueue left = new PriorityQueue<>(Collections.reverseOrder()); + PriorityQueue right = new PriorityQueue<>(); + + for (int i = 0; i < N; i++) { + int x = Integer.parseInt(br.readLine().trim()); + + left.offer(x); + + if (left.size() > right.size() + 1) { + right.offer(left.poll()); + } + + if (!right.isEmpty() && left.peek() > right.peek()) { + int a = left.poll(); + int b = right.poll(); + left.offer(b); + right.offer(a); + } + + sb.append(left.peek()).append('\n'); + } + + System.out.print(sb.toString()); + } +} + +```