From 70811eb174a0daa1212a7f0cbba99d8f2f1611e0 Mon Sep 17 00:00:00 2001 From: kokeunho <95072015+kokeunho@users.noreply.github.com> Date: Sat, 30 Nov 2024 12:57:17 +0900 Subject: [PATCH] =?UTF-8?q?2024-11-30/=EA=B0=80=EC=9A=B4=EB=8D=B0=EB=A5=BC?= =?UTF-8?q?=20=EB=A7=90=ED=95=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kokeunho/README.md | 1 + .../10-kokeunho.java" | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 "kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" diff --git a/kokeunho/README.md b/kokeunho/README.md index 351dac3..ebdf838 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -11,4 +11,5 @@ | 7차시 | 2024.11.12 | 구현 | [치킨 배달](https://www.acmicpc.net/problem/15686) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/25) | | 8차시 | 2024.11.17 | 구현 | [인구 이동](https://www.acmicpc.net/problem/16234) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/28) | | 9차시 | 2024.11.26 | 다이나믹 프로그래밍 | [계단 오르기](https://www.acmicpc.net/problem/2579) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/33) | +| 10차시 | 2024.11.30 | 자료구조 | [가운데를 말해요](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) | --- diff --git "a/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" "b/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" new file mode 100644 index 0000000..097b969 --- /dev/null +++ "b/kokeunho/\354\236\220\353\243\214\352\265\254\354\241\260/10-kokeunho.java" @@ -0,0 +1,35 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + StringBuilder sb = new StringBuilder(); + + int n = sc.nextInt(); + + PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); + PriorityQueue minHeap = new PriorityQueue<>(); + + for (int i = 0; i < n; i++) { + int num = sc.nextInt(); + + if (maxHeap.size() <= minHeap.size()) { + maxHeap.offer(num); + } else { + minHeap.offer(num); + } + + if (!minHeap.isEmpty() && maxHeap.peek() > minHeap.peek()) { + int little = minHeap.poll(); + int big = maxHeap.poll(); + + maxHeap.offer(little); + minHeap.offer(big); + } + sb.append(maxHeap.peek()).append("\n"); + } + System.out.println(sb); + } +} \ No newline at end of file