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