#C11011. Implementing a MinHeap with Dynamic Operations

    ID: 40281 Type: Default 1000ms 256MiB

Implementing a MinHeap with Dynamic Operations

Implementing a MinHeap with Dynamic Operations

In this problem, you are required to implement a min-heap data structure that supports two operations:\

  1. (insert(x)): Insert an integer (x) into the heap.\
  2. (extract_min()): Extract and print the smallest element from the heap. If the heap is empty, print (-1).\

You will be given a series of operations to perform on the heap. Your task is to process these operations and output the result of each extraction operation. This problem tests your understanding of heap data structures and priority queues.

inputFormat

The first line of input contains an integer (n) denoting the number of operations. Each of the next (n) lines describes an operation. An operation is either of the form "1 x" (without quotes) which means insert the integer (x) into the heap, or "2" (without quotes) which means extract the minimum element from the heap.

outputFormat

For each extraction operation (operation type 2), output the result on a new line. If an extraction is performed when the heap is empty, output (-1).## sample

8
2
1 3
1 1
2
1 2
2
2
2
-1

1 2 3 -1

</p>