-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_11289.cpp
More file actions
46 lines (42 loc) · 779 Bytes
/
back_11289.cpp
File metadata and controls
46 lines (42 loc) · 779 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
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;
struct cmp {
bool operator()(int a, int b)
{
if (abs(a) == abs(b))
{
return a > b;
}
return abs(a) > abs(b);
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue<int, vector<int>, cmp > pq;
int a;
cin >> a;
for (int i = 0; i < a; i++)
{
int v;
cin >> v;
if(v == 0)
{
if (pq.empty() == true)
cout << "0" << "\n";
else
{
cout << pq.top() << "\n";
pq.pop();
}
}
else
pq.push(v);
}
return 0;
}