https://www.acmicpc.net/problem/11286
#include <bits/stdc++.h>
using namespace std;
struct Data{
int val, val_abs;
Data(int a, int b) {
val = a;
val_abs = b;
}
bool operator< (const Data &d) const {
if (val_abs == d.val_abs) {
return val > d.val;
}
else {
return val_abs > d.val_abs;
}
}
};
priority_queue<Data> pQ;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "rt", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
if (a == 0) {
if (pQ.empty()) {
cout << 0 << '\n';
}
else {
cout << pQ.top().val << '\n';
pQ.pop();
}
}
else {
pQ.push(Data(a, abs(a)));
}
}
return 0;
}