Implement a Max Heap
Implement a max-heap supporting insertion, deletion, and heapify operations from scratch.
Input format
The first line contains Q. The next Q lines contain operations: push x, pop, top, or size.
Output format
For pop and top, print the maximum element. For size, print the heap size. Empty pop/top prints -1.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
22
size
push 37
push 93
push -16
pop
pop
push 59
size
pop
top
push 52
push -38
pop
size
top
pop
push -90
pop
pop
push -20
push -20
topExpected output
0
93
37
2
59
-16
52
2
-16
-16
-38
-90
-20Example 2
Input
27
push -45
pop
push 21
push -98
pop
top
top
pop
push 36
push 98
push 68
top
pop
top
push 57
size
size
size
push 31
pop
top
push -90
size
pop
push -78
pop
topExpected output
-45
21
-98
-98
-98
98
98
68
3
3
3
68
57
4
57
36
31