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)

/*
?????????????????\???

????????????????????\??? (priority queue) ??????????´??????????????????£????????????????????? S ?????????????????????????§??????§??????????¬????????????????????????????

    insert(S,k): ?????? S ???????´? k ????????\??????
    extractMax(S): ?????§?????????????????? S ???????´???? S ????????????????????????????????????

????????????????????\??? S ???????????? insert(S,k)???extractMax(S)?????????????????°????????????????????????????????????????????§???????????\??????????´??????´??°??¨?????????????????????????????¨??????????????????
??\???

????????????????????\??? S ???????????°????????????????????????????????????????????????insert k???extract?????????end?????¢?????§???????????????????????????????????????????????§ k ????????\????????´??°?????¨????????????

end???????????\?????????????????????????????????
??????

extract???????????¨??????????????????????????\??? S?????????????????????????????????????????????????????????????????? 
*/

#include <stdio.h>
#include <stdlib.h>
 #define N 2000002
#define NN 10
void Defin(int *, int);

void Defex(int *);

void Defma(int *, int);
 
int num = 0;
 
int main(){
  int i;
  int Arrayt[N];
  char Array[NN];
   
  while(1){

    scanf("%s", Array);

    if(Array[2] == 'd') 
      break;

    else if(Array[0] == 'i'){

      scanf("%d", &Arrayt[0]);

      Defin(Arrayt, Arrayt[0]);
    }
    else Defex(Arrayt);
  }
   
  return 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);
}