-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
54 lines (51 loc) · 1015 Bytes
/
11286.cpp
File metadata and controls
54 lines (51 loc) · 1015 Bytes
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
50
51
52
53
54
// 11286. 절댓값 힙
// 2021.04.24
// 자료구조
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
struct cmp {
bool operator()(pair<int, int>& a, pair<int, int>& b)
{
if (a.first == b.first)
{
return a.second > b.second;
}
return a.first > b.first;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> q;
int n, k;
cin >> n;
while (n-- > 0)
{
cin >> k;
if (k == 0)
{
if (q.empty())
{
cout << 0 << "\n";
}
else
{
cout << q.top().first * q.top().second << "\n";
q.pop();
}
}
else if (k > 0)
{
q.push({ abs(k), 1 });
}
else if (k < 0)
{
q.push({ abs(k), -1 });
}
}
return 0;
}