알고보니 1+2였다.
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
priority_queue<int, vector<int>> ansP;
priority_queue<int, vector<int>> ansN;
while (N--)
{
int tmp;
cin >> tmp;
if (tmp == 0) {
if (ansP.empty()&&ansN.empty())
cout << "0\n";
else {
if (ansN.empty()) {
cout << -1 * ansP.top() << endl;
ansP.pop();
}
else if (ansP.empty()) {
cout << ansN.top() << endl;
ansN.pop();
}
else if (-1 * ansP.top() < -1 * ansN.top()) {
cout << -1*ansP.top() << endl;
ansP.pop();
}
else {
cout << ansN.top() << endl;
ansN.pop();
}
}
}
else {
if (tmp > 0) {
ansP.push(-1 * tmp);
}
else {
ansN.push(tmp);
}
}
}
return 0;
}
'vidigummy KAU > 알고리즘 공부(백준!)' 카테고리의 다른 글
BOJ 9663 N-Queen (0) | 2021.01.16 |
---|---|
BOJ N과 M 시리즈 (0) | 2021.01.16 |
BOJ 11279/1927 최대힙/최소힙 (0) | 2021.01.14 |
BOJ 1202 보석도둑 (0) | 2021.01.14 |