-
Notifications
You must be signed in to change notification settings - Fork 0
/
qheap1.cpp
48 lines (45 loc) · 978 Bytes
/
qheap1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* https://www.hackerrank.com/challenges/qheap1/problem
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int q;
cin >> q;
vector<int> heap;
while (q--) {
int query;
cin >> query;
if (query == 1) {
int val;
cin >> val;
heap.push_back(val);
}
else if (query == 2) {
int val;
cin >> val;
auto it = heap.begin();
while (it != heap.end()) {
if (*it == val)
break;
++it;
}
heap.erase(it);
}
else {
auto it = heap.begin();
int min = *it;
while (it != heap.end()) {
if (*it < min)
min = *it;
++it;
}
cout << min << endl;
}
}
return 0;
}