Skip to content

Commit

Permalink
Merge pull request #36 from AlgoLeadMe/10-kokeunho
Browse files Browse the repository at this point in the history
10-kokeunho
  • Loading branch information
g0rnn authored Jan 2, 2025
2 parents 36a2da5 + 70811eb commit f36afbc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
35 changes: 35 additions & 0 deletions kokeunho/자료구조/10-kokeunho.java
Original file line number Diff line number Diff line change
@@ -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<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
PriorityQueue<Integer> 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);
}
}

0 comments on commit f36afbc

Please sign in to comment.