백준 11286 c++
#include <iostream>
#include <cstdlib>
#include <queue>
#include <climits>
#include <algorithm>
using namespace std;
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
//scanf("%d", &A);
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
struct compare {
bool operator()(int a, int b)//bool형이니까 a>b가 true or false로 나옴
//true면 a, false면 b
{
if (abs(a) == abs(b))
{
return a > b;//a가 b보다 작은게 true면 a, false면 b
}
else
{
return abs(a) > abs(b);
}
}
};
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, i, x, temp;
priority_queue<int, vector<int>, compare> absolute_heap;
N = input(1, 100000);
for (i = 0; i < N; i++)
{
x = input(INT_MIN, INT_MAX);
if (x == 0)
{
if (absolute_heap.size() == 0)
{
cout << "0\n";
}
else
{
cout << absolute_heap.top() << "\n";
absolute_heap.pop();
}
}
else
{
absolute_heap.push(x);
}
}
return 0;
}