Time limit
1s
Memory limit
128 MB
Write a program that manages a collection of natural numbers with a min-heap. The collection starts empty and must support the following operations.
x is given, insert x into the collection.0 is given, print the smallest value in the collection and remove that value. If the collection is empty, print 0.The first line contains the number of operations N (1 <= N <= 100,000). Each of the next N lines contains one integer x describing an operation.
If x is a natural number, insert x into the collection. If x is 0, print and remove the smallest value in the collection. Each x is either 0 or a natural number less than 2^31; negative integers are not given.
For each operation where 0 is given, print one line containing the result. If the collection is empty when a print-and-remove operation is requested, print 0.