백준 7662
set을 이용해서 풀었다.
우선순위 큐를 최대힙과 최소힙 두개 준비해서 풀어도 된다.
#include <bits/stdc++.h>
#include<set>
using namespace std;
int t;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> t;
while (t--) {
multiset<int> s;
int n;
cin >> n;
while (n--) {
string s1;
int k;
cin >> s1 >> k;
if (s1 == "I") {
s.insert(k);
}
else {
if (k == 1) {
if (s.empty()) continue;
auto it = --s.end();
s.erase(it);
}
else {
if (s.empty()) continue;
auto it = s.begin();
s.erase(it);
}
}
}
if (s.empty()) cout << "EMPTY" << '\n';
else {
cout << *(--s.end()) << ' ' << *(s.begin()) << '\n';
}
}
}