-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_11279.cpp
More file actions
111 lines (101 loc) · 2.08 KB
/
back_11279.cpp
File metadata and controls
111 lines (101 loc) · 2.08 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// #include <iostream>
// using namespace std;
// int M_heap[100001];
// int pivot = 1;
// void pop()
// {
// if (pivot == 1)
// {
// cout << "0" << "\n";
// return ;
// }
// cout << M_heap[1] << "\n";
// pivot--;
// if (pivot == 1)
// return ;
// int parent = 1;
// int child = 2;
// M_heap[1] = M_heap[pivot];
// while (child <= pivot)
// {
// if (M_heap[parent] < M_heap[child] && M_heap[child] < M_heap[child + 1])
// child++;
// if (M_heap[child] < M_heap[parent])
// break;
// int temp = M_heap[parent];
// M_heap[parent] = M_heap[child];
// M_heap[child] = temp;
// parent = child;
// child *= 2;
// }
// }
// void push(int num)
// {
// int c;
// M_heap[pivot++] = num;
// c = pivot - 1;
// while (c != 1)
// {
// if(M_heap[c] > M_heap[c/2])
// {
// int temp = M_heap[c];
// M_heap[c] = M_heap[c/2];
// M_heap[c/2] = temp;
// c /= 2;
// }
// else
// break;
// }
// for (int i = 0; i < pivot; i++)
// {
// cout << M_heap[i] << ", ";
// }
// }
// int main()
// {
// ios::sync_with_stdio(false);
// cin.tie(NULL);
// cout.tie(NULL);
// int a;
// cin >> a;
// for (int i = 0; i < a; i++)
// {
// int b;
// cin >> b;
// if (b == 0)
// pop();
// else
// push(b);
// }
// return 0;
// }
#include <iostream>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue<int> 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;
}