Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- vector<int> heap;
- int commands;
- string option;
- int number;
- cin >> commands;
- for (int i = 0; i < commands; i++) {
- cin >> option;
- if (option == "push") {
- cin >> number;
- heap.push_back(number);
- push_heap(heap.begin(), heap.end());
- }
- if (option == "pop") {
- if (!heap.empty()) {
- pop_heap(heap.begin(), heap.end());
- heap.pop_back();
- }
- }
- if (option == "top") {
- if (!heap.empty()) {
- cout << heap.front() << endl;
- }
- }
- }
- cout << "all done" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement