Advertisement
Emiliatan

a513

May 28th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. /* a513             */
  2. /* AC (11ms, 152KB) */
  3. #include <cstdio>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int T, n, m, x;
  9. int pq[40000], index = 0;
  10.  
  11. int main()
  12. {
  13.     scanf("%d", &T);
  14.  
  15.     for(int kase = 1; kase <= T; ++kase)
  16.     {
  17.         scanf("%d %d", &n, &m);
  18.         printf("Case %d:\n", kase);
  19.  
  20.         while(n-- && scanf("%d", &pq[index++]));
  21.         make_heap(pq, pq + index);
  22.  
  23.         while(m-- && scanf("%d", &x))
  24.         {
  25.             if(x == 1)
  26.             {
  27.                 scanf("%d", &pq[index++]);
  28.                 push_heap(pq, pq + index);
  29.             }
  30.             else
  31.             {
  32.                 if(index)
  33.                 {
  34.                     printf("Max: %d\n", pq[0]);
  35.                     pop_heap(pq, pq + index--);
  36.                 }
  37.                 else
  38.                     puts("It's empty!");
  39.             }
  40.         }
  41.         if(index)
  42.             while(index)
  43.             {
  44.                 printf("%d ", pq[0]);
  45.                 pop_heap(pq, pq + index--);
  46.             }
  47.         else
  48.             printf("It's empty!");
  49.         putchar('\n');
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement