Skip to content

Commit f09ae8e

Browse files
authored
Merge pull request #1377 from AlgorithmWithGod/lkhyun
[20251111] BOJ / G2 / 가운데를 말해요 / 이강현
2 parents 6d97c7e + 261c155 commit f09ae8e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringBuilder sb = new StringBuilder();
9+
static int N;
10+
static PriorityQueue<Integer> minheap = new PriorityQueue<>();
11+
static PriorityQueue<Integer> maxheap = new PriorityQueue<>(Comparator.reverseOrder());
12+
public static void main(String[] args) throws Exception {
13+
N = Integer.parseInt(br.readLine());
14+
15+
for(int i = 0; i<N; i++){
16+
maxheap.offer(Integer.parseInt(br.readLine()));
17+
minheap.offer(maxheap.poll());
18+
if(maxheap.size()< minheap.size()){
19+
maxheap.offer(minheap.poll());
20+
}
21+
bw.write(maxheap.peek()+"\n");
22+
}
23+
bw.close();
24+
}
25+
}
26+
```

0 commit comments

Comments
 (0)