-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11286.cpp
More file actions
40 lines (38 loc) · 900 Bytes
/
11286.cpp
File metadata and controls
40 lines (38 loc) · 900 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int N;
priority_queue<int,vector<int>,greater<int>> min_heap;
map<int,int> nums;
cin>>N;
for(int i=0;i<N;i++){
int x;
cin>>x;
if(x==0){
if(min_heap.empty())cout<<"0\n";
else {
if(nums[min_heap.top()*-1]>0){
cout<<min_heap.top()*-1<<'\n';
nums[min_heap.top()*-1]--;
}
else {
cout<<min_heap.top()<<'\n';
nums[min_heap.top()]--;
}
min_heap.pop();
}
}else {
nums[x]++;
if(x<0) x*=-1;
min_heap.push(x);
}
}
return 0;
}