inlineintread(){ registerchar c; while (c = getchar(), c < '0' || c>'9'); registerintx(c - '0'); while (c = getchar(), c >= '0' && c <= '9') { x = x * 10 + c - '0'; } return x; }
int heap[MAXn+10]; int heapn; int n; voidup(int p){ int f = p / 2; while (p > 1) { if (heap[p] < heap[f]) { swap(heap[p], heap[f]); p = f; f /= 2; } elsebreak; } } voiddown(int p){ int s = p * 2; while (s <= heapn) { if (heap[s] > heap[s + 1] && s < heapn) { s++; } if (heap[s] < heap[p]) { swap(heap[s], heap[p]); p = s; s *= 2; } elsebreak; } } voidinsert(int x){ heap[++heapn] = x; up(heapn); } voidpop(int p){ heap[p] = heap[heapn--]; up(p); down(p); } voidpop_root(){ heap[1] = heap[heapn--]; down(1); } intget_root(){ return heap[1]; }
intmain(){ n = read(); for(int i = 0; i < n; i++) { insert(read()); } for(int i = 0; i < n; i++) { printf("%d ", get_root()); pop_root(); } }