Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- #include <climits>
- #include <stdio.h>
- #include <iomanip>
- #include <stack>
- #define F first
- #define S second
- using namespace std;
- long a[200000];
- int n;
- void siftup(long i)
- {
- while (i > 0 && a[i] > a[i / 2])
- {
- swap(a[i], a[i / 2]);
- i /= 2;
- }
- }
- void siftdown(long i)
- {
- int j;
- while (i * 2 < n)
- {
- j = i;
- if (a[i * 2] > a[j])
- j = i * 2;
- if (i * 2 + 1 < n && a[i * 2 + 1] > a[j])
- j = i * 2 + 1;
- if (i == j)
- break;
- swap(a[i], a[j]);
- i = j;
- }
- }
- void ins(long i)
- {
- a[n] = i;
- siftup(n);
- // n++;
- }
- void del(long i)
- {
- a[0] = a[n - 1];
- n--;
- siftdown(0);
- }
- int main()
- {
- freopen("input.txt","r", stdin);
- freopen("output.txt", "w",stdout);
- string s;
- int x;
- n = 0;
- while (cin >> s)
- {
- //cout << n << endl;
- //cout << s << endl;
- if (s == "ADD")
- {
- cin >> x;
- ins(x);
- n++;
- }
- if (s == "EXTRACT")
- if (n == 0)
- cout << "CANNOT" << endl;
- else
- {
- cout << a[0] << endl;
- del(0);
- }
- if (s == "CLEAR")
- while(n != 0)
- del(0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement