728x90
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include <functional>
using namespace std;
int main() {
int n;
cin >> n;
int x;
priority_queue<pair<int,int>,vector<pair<int,int>>, greater<pair<int, int>>> pq;
vector<int>ans;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 0) {
if (pq.empty()) { ans.push_back(0); continue; }
int t = pq.top().first;
int mn = pq.top().second;
if (mn < 0) {
ans.push_back(-t);
}
else {
ans.push_back(t);
}
pq.pop();
}
else {
if (x < 0) {
pq.push(make_pair(-x,-1));
}
else {
pq.push(make_pair(x, 1));
}
}
}
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
}
'백준 > 힙' 카테고리의 다른 글
보석 도둑 -1202번 (0) | 2021.09.09 |
---|