#include #include #include using namespace std; struct Heap { int* a; static const int MAX = 100000; int size; Heap( int* x , int sz ) { size = sz; a = new int[MAX + 1]; for (int i=1 ; i<=sz ; i++) a[i] = x[i]; } void BuildHeap() { int p = size / 2; for ( int i=p ; i>=1 ; i--) Heapify(i); } void Heapify(int i) { while (true) { int l = i*2; int r = i*2+1; int g = i; // farz konim kuchiktarin adad pedare if ( l<=size && a[l] pas nemishe bishtar az in edame dad break; } } void DecreaseValue(int p , int val) { if ( p < 1 || p > size ) return ; if ( val > a[p] ) return; a[p] = val; while ( p>1 ) { if ( a[p] < a[p/2] ) { swap(a[p] , a[p/2]); p = p/2; } else break; } } void Insert(int val) { // Check Kardane Size Arraye size++; a[size] = val; DecreaseValue( size , val ); } int Delete() { if (size < 1) return -1; int copy = a[1]; swap(a[size] , a[1]); size--; Heapify(1); // Check Kardane Size Arraye return copy; } /*void Heapify(int p) { while (true) { int l = p*2; int r = p*2 + 1; if (l > size && r > size) break; int vl , vr; if ( r > size ) { if ( a[l] < a[p] ) { swap(a[l] , a[p]); p = l; } else break; } else { int v = a[l]=0 && k<=size ; i--,j++) { int c = t[j]; // Num of numbers in current row int out_space = t[i]; // Space of left side int in_space = (t[i+1]-1); // Space between numbers cout<