File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments