#include<iostream>
using namespace std;
#include<vector>
class heap{
vector<int> pq;
public:
void push(int val){
// insert the value in the vector
pq.push_back(val); // O(1);
// fix the heap O(log n);
int childidx = pq.size()-1;
int parentidx = (childidx-1)/2;
while(parentidx>=0 && pq[childidx]>pq[parentidx]){
swap(pq[childidx],pq[parentidx]);
childidx = parentidx;
parentidx = (childidx-1)/2;
}
}
int top(){
return pq[0];
}
bool empty(){
return pq.size()==0;
}
};
int main(){
heap pq;
pq.push(10);
pq.push(100);
pq.push(50);
cout<<"top: "<<pq.top()<<endl;
cout<<pq.empty();
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNpbmNsdWRlPHZlY3Rvcj4KCmNsYXNzIGhlYXB7CiAgICB2ZWN0b3I8aW50PiBwcTsKICAgIHB1YmxpYzoKICAgIAogICAgdm9pZCBwdXNoKGludCB2YWwpewogICAgICAgIC8vIGluc2VydCB0aGUgdmFsdWUgaW4gdGhlIHZlY3RvcgogICAgICAgIHBxLnB1c2hfYmFjayh2YWwpOyAgICAgIC8vIE8oMSk7CiAgICAgICAgLy8gZml4IHRoZSBoZWFwICAgICAgIE8obG9nIG4pOwogICAgICAgIAogICAgICAgIGludCBjaGlsZGlkeCA9IHBxLnNpemUoKS0xOwogICAgICAgIGludCBwYXJlbnRpZHggPSAoY2hpbGRpZHgtMSkvMjsKICAgICAgICAKICAgICAgICB3aGlsZShwYXJlbnRpZHg+PTAgJiYgcHFbY2hpbGRpZHhdPnBxW3BhcmVudGlkeF0pewogICAgICAgICAgICBzd2FwKHBxW2NoaWxkaWR4XSxwcVtwYXJlbnRpZHhdKTsKICAgICAgICAgICAgY2hpbGRpZHggPSBwYXJlbnRpZHg7CiAgICAgICAgICAgIHBhcmVudGlkeCA9IChjaGlsZGlkeC0xKS8yOwogICAgICAgIH0KICAgIH0KICAgIAogICAgaW50IHRvcCgpewogICAgICAgIHJldHVybiBwcVswXTsKICAgIH0KICAgIAogICAgYm9vbCBlbXB0eSgpewogICAgICAgIHJldHVybiBwcS5zaXplKCk9PTA7CiAgICAgICAgfQp9OwoKaW50IG1haW4oKXsKICAgIGhlYXAgcHE7CiAgICBwcS5wdXNoKDEwKTsKICAgIHBxLnB1c2goMTAwKTsKICAgIHBxLnB1c2goNTApOwogICAgCiAgICBjb3V0PDwidG9wOiAiPDxwcS50b3AoKTw8ZW5kbDsKICAgIGNvdXQ8PHBxLmVtcHR5KCk7Cn0=