Skip to content
Merged
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
26 changes: 26 additions & 0 deletions lkhyun/202511/11 BOJ G2 가운데를 말해요.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
```java
import java.util.*;
import java.io.*;

public class Main{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringBuilder sb = new StringBuilder();
static int N;
static PriorityQueue<Integer> minheap = new PriorityQueue<>();
static PriorityQueue<Integer> maxheap = new PriorityQueue<>(Comparator.reverseOrder());
public static void main(String[] args) throws Exception {
N = Integer.parseInt(br.readLine());

for(int i = 0; i<N; i++){
maxheap.offer(Integer.parseInt(br.readLine()));
minheap.offer(maxheap.poll());
if(maxheap.size()< minheap.size()){
maxheap.offer(minheap.poll());
}
bw.write(maxheap.peek()+"\n");
}
bw.close();
}
}
```