Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10-kokeunho #36

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}