Problem:
Priority Queue
A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations:
$insert(S, k)$: insert an element $k$ into the set $S$
$extractMax(S)$: remove and return the element of $S$ with the largest key
Write a program which performs the $insert(S, k)$ and $extractMax(S)$ operations to a priority queue $S$.
  The priority queue manages a set of integers, which are also keys for the priority.
Input
Multiple operations to the priority queue $S$ are given. Each operation is given by "
insert
$k$", "
extract
" or "
end
" in a line. Here, $k$ represents an integer element to be inserted to the priority queue.
The input ends with "
end
" operation.
Output
For each "
extract
" operation, print the element extracted from the priority queue $S$ in a line.
Constraints
The number of operations $\leq 2,000,000$
$0 \leq k \leq 2,000,000,000$
Sample Input 1
insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end
Sample Output 1
8
10
11
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long
const int mod = 1000000007;
#define srt(v) sort(v.begin(), v.end());
#define srt_Dec(v) sort(v.begin(), v.end(), greater<int>());

int solve1(){

    return 0;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    string s;
    priority_queue<int> pq;
    while(cin>>s){
        if (s == "insert"){
            int n;
            cin >> n;

            pq.push(n);
        }
        else if (s == "extract"){
            cout << pq.top() << "\n";
            pq.pop();
        }

        else if(s=="end"){
            break;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 11428
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    priority_queue<long long> pq;  
    string cmd;
    while(cin>>cmd){
        if(cmd=="insert"){
            long long k;
            cin>>k;
            pq.push(k);
        }
        else if(cmd=="extract"){
            long long mx=pq.top();
            pq.pop();
            cout<<mx<<"\n";
        }
        else if(cmd=="end"){
            break;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 11460
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define ll long long
#define dd double

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    int k;
    priority_queue<int> pq;
    while(cin >> s && s != "end"){
        if(s == "insert"){
            cin >> k;
            pq.push(k);
        }else{
            cout << pq.top() << endl;
            pq.pop();
        }
    }

    return 0;
}
accuracy: 1
time_ms: 570
memory_kb: 7760
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main()
{
    priority_queue<int>p;
    while(1)
    {
        string c;
        cin >> c;

        if (c=="end")
        {
            break;
        }
        else if (c=="insert")
        {
            int n;
            cin >> n;
            p.push(n);
        }
        else if (c=="extract")
        {
            int topValue=p.top();
            cout << topValue << "\n";
            p.pop();
        }
    }
}
accuracy: 1
time_ms: 900
memory_kb: 8796
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue<int> PQ;
    while(1)
    {
        string str;
        cin>>str;
        if(str=="end")break;
        else if(str=="insert")
        {
            int value;
            cin>>value;
            PQ.push(value);
        }
        else if(str=="extract")
        {
            cout<<PQ.top()<<endl;
            PQ.pop();
        }

    }
}
accuracy: 1
time_ms: 900
memory_kb: 7560
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{ priority_queue<long long >pq;

    string s;
    long long a;
    while(cin>>s)
    {
        if(s=="insert")
        {
            cin>>a;
            pq.push(a);
        }
        else if(s=="extract")
        {
            long long mx=pq.top();
            pq.pop();
            cout<<mx<<endl;
        }
        else if(s=="end")
        {
            break;
        }
    }





}
accuracy: 1
time_ms: 900
memory_kb: 11764
final_rank: 20

code_snippet: #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
using ld = long double;
ll INF = 2e18;
#define PI 3.14159265358979323846264338327950l
// namespace multip = boost::multiprecision;
// using lll = multip::int128_t;
using P = pair<ll, ll>;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>; using vvvvl = vv<vvl>;
using vs = vc<string>; using vvs = vv<string>;
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define drep(i,n) for (ll i = (n)-1; i >= 0; i--)
#define nfor(i, s, n) for (ll i = (s); i < (n); i++)
#define dfor(i, s, n) for (ll i = (s)-1; i>=n; i--)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define em emplace
#define pob pop_back
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define YN { cout << "Yes" << endl; } else { cout << "No" << endl; }
#define dame cout << -1 << endl
#define minval(vec) *min_element(nall(vec))
#define maxval(vec) *max_element(nall(vec))
#define binaryS(vec, x) *lower_bound(nall(vec), x)
#define yu_qurid(x, y) (x) * (x) + (y) * (y)
#define mannhattan(x1, x2, y1, y2) abs(x1-x2)+abs(y1-y2)
#define vc_cout(v){ll n= size(v); rep(i,n)cout<<v[i]<<" ";cout << endl;}
#define vvc_cout(v){ll n= size(v);rep(i,n){rep(j,size(v[i])){cout<<v[i][j]<<" ";}cout<<endl;}}
// 少数の出力
void print(ld x) { printf("%.20Lf\n", x); }

// グリット用
vector<ll> dx = {1, 0, -1, 0};
vector<ll> dy = {0, 1, 0, -1};
bool in_grid(ll i, ll j, ll h, ll w) {
    return 0 <= i and i < h and 0 <= j and j < w;
}

vector<ll> pq = {-1};
ll used = 0;


void set_heap(ll k) {
    pq.push_back(k);
    ++used;
    ll point = used;
    while (point > 1 and  pq[point / 2] < pq[point]) {
        swap(pq[point], pq[point / 2]);
        point = point / 2;
    }
}
// 節点iを根とする部分木がmax-ヒープとなるようA[i]の値をmax-ヒープの葉へ向かって下降させる
void maxHeapify(ll i) {
    ll left = i * 2;
    ll right = i * 2 + 1;
    // 左の子, 右の子, 自分で値が最大なノードを選ぶ
    ll largest = i;
    if (left <= used and pq[left] > pq[largest]) {
        largest = left;
    }
    if (right <= used and pq[right] > pq[largest]) {
        largest = right;
    }
    // iの子の方が大きかったら
    if (largest != i) {
        swap(pq[i], pq[largest]);
        maxHeapify(largest);
    }
}

// main
void solve() {
    // 最大ヒープを使って優先度付きキューを作成する
    string type;
    while (1) {
        cin >> type;
        if (type == "end") break;
        else if (type == "insert") {
            ll k;
            cin >> k;
            set_heap(k);
        }
        else if (type == "extract") {
            cout << pq[1] << endl;
            pq[1] = pq[used];
            pq.pop_back();
            used--;
            maxHeapify(1);
        }
    }

    return;
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 650
memory_kb: 11740
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define endl "\n"

const ll MOD = 1e7 + 9;
const ll INF = 1e18;
const int MX = 100001;

void solve2() {
    priority_queue<int> PQ;

    while(true) {
        string S; cin >> S;
        if(S == "end") break;
        else if(S == "insert") {
            int N;
            cin >> N;
            PQ.push(N);
        }
        else if (S == "extract") {
            if(!PQ.empty()) {
                cout << PQ.top() <<endl;
                PQ.pop();
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    //cin >> T;
    while(T--) solve2();

   
    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 8116
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);cout.tie(nullptr);

 
 priority_queue<int>pq;
 while(1){
    string type;
    cin>>type;
    if(type=="insert"){
        int x;
        cin>>x;
        pq.push(x);
    }

    else if(type=="extract"){
        cout<<pq.top()<<"\n";
        pq.pop();
    }

    else if(type=="end"){
        return 0;
    }
 }


 return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 9156
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

priority_queue<int> pq;
string s;
int k;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    while(cin >> s) {
        if(s == "end") break;
        if(s == "insert") {
            cin >> k;
            pq.push(k);
        }else {
            cout << pq.top() << '\n';
            pq.pop();
        }
    }

    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 8184
final_rank: 3

code_snippet: #include <iostream>
#include <algorithm>
#include <string>

constexpr int MAX = 2000000;
constexpr int INFTY = 1 << 30;

void maxHeapify(int A[], int& H, int i) {
    while (true) {
        int l = 2 * i;
        int r = 2 * i + 1;
        int largest = i;
        if (l <= H && A[l] > A[largest]) largest = l;
        if (r <= H && A[r] > A[largest]) largest = r;
        if (largest == i) break;
        std::swap(A[i], A[largest]);
        i = largest;
    }
}

int extract(int A[], int& H) {
    if (H < 1) return -INFTY;
    int maxv = A[1];
    A[1] = A[H--];
    maxHeapify(A, H, 1);
    return maxv;
}

void increaseKey(int A[], int i, int key) {
    if (key < A[i]) return;
    A[i] = key;
    while (i > 1 && A[i / 2] < A[i]) {
        std::swap(A[i], A[i / 2]);
        i /= 2;
    }
}

void insert(int A[], int& H, int key) {
    A[++H] = -INFTY;
    increaseKey(A, H, key);
}

int main() {
    static int A[MAX + 1];
    int H = 0;

    std::string com;
    int key;

    while (true) {
        if (!(std::cin >> com)) break;

        if (com.size() >= 2 && com[0] == 'e' && com[1] == 'n') {
            break;
        } else if (!com.empty() && com[0] == 'i') {
            std::cin >> key;
            insert(A, H, key);
        } else {
            std::cout << extract(A, H) << '\n';
        }
    }

    return 0;
}
accuracy: 1
time_ms: 890
memory_kb: 7424
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int CAPACITY = 2000000;
int H = 0;

void swap(vector<int>& a, int x, int y)
{
    int tmp = a[x];
    a[x] = a[y];
    a[y] = tmp;
}


void max_heapify(vector<int>& a, int i)
{
    int l_id = i*2;
    int r_id = i*2+1;

    int largest_id = i;
    if(l_id <= H && a[l_id] > a[largest_id])
        largest_id = l_id;
    if(r_id <= H && a[r_id] > a[largest_id])
        largest_id = r_id;

    if(largest_id != i)
    {
        swap(a, i, largest_id);
        max_heapify(a, largest_id);
    }
}

void insert(vector<int>& a, int k)
{
    H++;
    int i = H;
    a[i] = k;
    while(i > 1 && a[i/2] < a[i])
    {
        swap(a, i, i/2);
        i /= 2;
    }
}

void extract(vector<int>& a)
{
    cout << a[1] << endl;
    a[1] = a[H];
    a[H] = -1;
    H--;
    max_heapify(a, 1);
}

int main()
{
    vector<int> a(CAPACITY + 1);
    for(int i = 0; i <= CAPACITY; i++)
        a[i] = -1;

    bool end = false;
    while(!end)
    {
        char op[10];
        scanf("%s", op);
        if(op[0] == 'i')
        {
            int k;
            scanf("%d", &k);
            insert(a, k);
        }
        if(op[0] == 'e' && op[1] == 'x')
        {
            extract(a);
        }
        if(op[0] == 'e' && op[1] == 'n')
            end = true;
    }
}
accuracy: 1
time_ms: 580
memory_kb: 10584
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    priority_queue<int> pq;
    while (cin >> s)
    {
        if (s == "insert")
        {
            cin >> n;
            pq.push(n);
        }
        else if (s == "extract")
        {
            cout << pq.top() << "\n";
            pq.pop();
        }
        else if (s == "end")
            break;
    }
}
accuracy: 1
time_ms: 890
memory_kb: 8620
final_rank: 15

code_snippet: #include <queue>
#include <string>
#include <iostream>
using namespace std;

int main() {
    string cmd; // whileの外側で定義して一つの変数を再利用する
    priority_queue<int> Q;

    while (cin >> cmd && cmd != "end") {
        if (cmd == "insert") {
            int k;
            cin >> k;
            Q.push(k);
        } else if (cmd == "extract") {
                cout << Q.top() << endl;
                Q.pop();
        }
    }
}
accuracy: 1
time_ms: 910
memory_kb: 7704
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <tuple>
#include <utility>
#include <iterator>
#include <limits>
#include <functional>
#include <array>
#include <type_traits>
#include <chrono>
#include <list>
#include <forward_list>
#include <complex>
#include <typeinfo>
#include <stdexcept>

using namespace std;

inline void Fast_IO() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define endl '\n'
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define ft first
#define sd second


void solve(){
    
    priority_queue<ll> pq;

    while(true){
        string str;
        cin >> str;

        if(str == "end"){
            break;
        }

        if(str == "insert"){
            ll x;
            cin >> x;

            pq.push(x);
        }

        if(str == "extract"){
            cout << pq.top() << endl;
            pq.pop();
        }
    }
    
}


int main(){

    Fast_IO();

    solve();

    return 0;
}
accuracy: 1
time_ms: 310
memory_kb: 12900
final_rank: 12

code_snippet: #include <queue>
#include <string>
#include <iostream>
using namespace std;
int main() {
    string cmd; // \texttt{while}の外側で定義して一つの変数を再利用する
    priority_queue<int> Q;
    while (cin >> cmd && cmd != "end") {
        if (cmd == "insert") {
            int k;
            cin >> k;
            Q.push(k); // 集合 Sに要素 kを挿入する
        } else if (cmd == "extract") {
            // 最大のキーを持つ Sの要素を Sから削除してその値を返す
            cout << Q.top() << endl;
            Q.pop();
        }
        }
    }
accuracy: 1
time_ms: 900
memory_kb: 8772
final_rank: 16

code_snippet: #include <queue> 
#include <string> 
#include <iostream> 
using namespace std;

int main() { 
    string cmd; // \texttt{while}の外側で定義して一つの変数を再利用する 
    priority_queue<int> Q; 
    while (cin >> cmd && cmd != "end") { 
        if (cmd == "insert") { 
        // 何かする 
        int x;
        cin >> x;
        Q.push(x);
        } else if (cmd == "extract") { 
        // 何かする 
        cout << Q.top() << endl;
        Q.pop();
        } 
    } 
}
accuracy: 1
time_ms: 900
memory_kb: 7312
final_rank: 8

code_snippet: #include <iostream>
#include <queue>
using namespace std;

int main(){
    string cmd;
    priority_queue<int> que;
    while(cin >> cmd){
        if (cmd == "end"){
            break;
        }
        if (cmd == "insert"){
            int x;
            cin >> x;
            que.push(x);
        }else if(cmd == "extract"){
            int x = que.top();
            que.pop();
            cout << x << endl;
        }
    }
}
accuracy: 1
time_ms: 900
memory_kb: 8900
final_rank: 18

code_snippet: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INF (1<<20)

int H, A[MAX+1];

int parent(int k) { return k / 2; }
int left(int k) { return 2 * k; }
int right(int k) { return 2 * k + 1; }

void maxHeapify(int k, int B[], int h) {
    int largest = k;
    if ( left(k) <= h && B[k] < B[left(k)] ) largest = left(k);
    if ( right(k) <= h && B[largest] < B[right(k)] ) largest = right(k);
    if ( largest != k ) {
        swap(B[k], B[largest]);
        maxHeapify(largest, B, h);
    }
}

void buildMaxHeap(int B[], int h) {
    for (int i = h / 2; i > 0; i--) {
        maxHeapify(i, B, h);
    }
}

void heepIncreaseKey(int i, int key) {
    A[i] = key;
    while ( i > 1 && A[parent(i)] < A[i]) {
        swap(A[parent(i)], A[i]);
        i = parent(i);
    }
}

void insert(int k) {
    H++;
    A[H] = -INF;
    heepIncreaseKey(H, k);
}

void extract() {
    printf("%d\n", A[1]);
    A[1] = A[H];
    H--;
    maxHeapify(1, A, H);

}

int main() {
    H = 0;
    int k;
    char com[10];
    while ( true ) {
        scanf("%s", com);
        if ( com[0] == 'i' ) {
            scanf("%d", &k);
            insert(k);
        }
        else if ( com[1] == 'x' ) extract();
        else return 0;
    }
}
accuracy: 1
time_ms: 220
memory_kb: 6892
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
      priority_queue<int>p;
    while(1){
        cin>>s;
        if(s=="insert"){
            int x;
            cin>>x;
            p.push(x);

            
        }
        else if(s=="extract"){
            cout<<p.top()<<endl;
            p.pop();
            
        }
        else if(s=="end") break;
       
        
    }
}
accuracy: 1
time_ms: 890
memory_kb: 7764
final_rank: 11