Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Priority Queue

A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations:

$insert(S, k)$: insert an element $k$ into the set $S$

$extractMax(S)$: remove and return the element of $S$ with the largest key

Write a program which performs the $insert(S, k)$ and $extractMax(S)$ operations to a priority queue $S$.
The priority queue manages a set of integers, which are also keys for the priority.

Input

Multiple operations to the priority queue $S$ are given. Each operation is given by "insert $k$", "extract" or "end" in a line. Here, $k$ represents an integer element to be inserted to the priority queue.

The input ends with "end" operation.

Output

For each "extract" operation, print the element extracted from the priority queue $S$ in a line.

Constraints

The number of operations $\leq 2,000,000$

$0 \leq k \leq 2,000,000,000$

Sample Input 1

insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end

Sample Output 1

8
10
11
2

Solution in C (judge verdict: Accepted)

        #include <stdio.h>
        #include <stdlib.h>

        #define N 2000002
        #define M 10

        int NUM = 0;

        void Defma(int *t, int i){

            int left, right;
            int  large, c;

            if( i * 2 + 1 < NUM + 1) right = i * 2 + 1;
            else right = i;

            if( i * 2 < NUM + 1)
                left = i * 2;
            else left = i;

            if(left <= NUM && t[left] > t[i])
                large = left;
            else large = i;

            if(right <= NUM && t[right] > t[large])
                large = right;

            if(large != i){
                c = t[i];
                t[i] = t[large];
                t[large] = c;

                Defma(t, large);
            }
        }

        void Defin(int *arrayt, int z){

            int i,c;

            NUM++;
            i = NUM;
            arrayt[NUM] = z;

            while(i > 1 && arrayt[i/2] < arrayt[i]){

                c = arrayt[i];

                arrayt[i] = arrayt[i/2];

                arrayt[i/2] = c;


                i /= 2;
            }
        }

        void Defex(int *arrayt){

            printf("%d\n", arrayt[1]);

            if(NUM > 1) arrayt[1] = arrayt[NUM];

            NUM--;

            if(NUM > 1) Defma(arrayt, 1);
        }

        int main(){

            int i;
            int AI[N];
            char AC[M];

            while(1){

                scanf("%s", AC);

                if(AC[2] == 'd') break;
                else if(AC[0] == 'i'){
                    scanf("%d", &AI[0]);
                    Defin(AI, AI[0]);
                }

                
                else Defex(AI);
            }

            return 0;
        }