Advertisement
SuitNdtie

Machine PROG 1021

Mar 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<queue>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int k,i,x,ai;
  9.     ai = 0;
  10.     priority_queue<int> pq;
  11.     scanf("%d",&k);
  12.     int ans[k];
  13.     i=0;
  14.     char c;
  15.     while(i<k){
  16.         scanf(" %c",&c);
  17.         if(c == 'P'){
  18.             scanf("%d",&x);
  19.             pq.push(x);
  20.         }else if(c == 'Q'){
  21.             if(pq.empty()){
  22.                 ans[ai] = -1;
  23.             }
  24.             else{
  25.                 ans[ai] = pq.top();
  26.                 pq.pop();
  27.             }
  28.             ai = ai + 1;
  29.         }
  30.         i = i + 1;
  31.     }
  32.    
  33.     i = 0;
  34.     while(i < ai){
  35.         printf("%d\n",ans[i]);
  36.         i = i + 1;
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement