-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day49.java
38 lines (30 loc) · 1.06 KB
/
Day49.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// PriorityQueue
// https://www.interviewbit.com/problems/priorityqueue/
import java.lang.*;
import java.util.*;
public class Day49 {
public static void main(String[] args) {
// YOUR CODE GOES HERE
// Please take input and print output to standard input/output (stdin/stdout)
// DO NOT USE ARGUMENTS FOR INPUTS
// E.g. 'Scanner' for input & 'System.out' for output
Scanner scan = new Scanner(System.in);
int query = scan.nextInt();
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int i = 0; i < query; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
switch(x) {
case 1 :
pq.add(y);
break;
case 2 :
if(pq.peek() == null) System.out.println(-1);
else System.out.println(pq.peek());
break;
case 3 : if(pq.peek() != null) pq.poll();
break;
}
}
}
}