#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(int argc, char **argv) {
  int heap[10];
  for(int i=0; i<10; i++)
    heap[i] = rand()%100;

  for(int i=0; i<10; i++)
    cout << heap[i] << ' ';
  cout << '\n';

  make_heap(heap, heap+10, greater<int>());

  for(int n=10; n>0; n--) {
    for(int i=0; i<n; i++)
      cout << heap[i] << ' ';
    cout << '\n';

    pop_heap(heap, heap+n, greater<int>());
  }

  return 0;
}
