-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqheap_hackerrank.cpp
More file actions
49 lines (48 loc) · 1.06 KB
/
qheap_hackerrank.cpp
File metadata and controls
49 lines (48 loc) · 1.06 KB
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
48
49
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
/*STDIN Function
----- --------
5 Q = 5
1 4 insert 4
1 9 insert 9
3 print minimum
2 4 delete 4
3 print minimum*/
int main()
{
int num, ope, para;
std::cin >> num; // 5
std::priority_queue<int, std::vector<int>, std::greater<int>> pq, pq2;
for (int i = 1; i <= num; i++)
{
std::cin >> ope;
if (ope == 1)
{
std::cin >> para; // check if needs to reset ?
pq.push(para);
}
else if (ope == 2)
{
std::cin >> para;
pq2.push(para);
}
else
{
while (!pq.empty() && !pq2.empty() && pq.top() == pq2.top())
{
pq.pop();
pq2.pop();
}
// if pq is empty ?
// if top !=top
std::cout << pq.top() << endl;
}
}
return 0;
}