백준
이중우선순위큐
연구하는개발자
2021. 4. 5. 20:51
728x90
7662번: 이중 우선순위 큐
입력 데이터는 표준입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫째 줄에는 Q에 적
www.acmicpc.net
#include<iostream>
#include<set>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t; cin >> t;
while (t--) {
multiset<int>arr;
int n; cin >> n;
for (int i = 0; i < n; i++) {
char a; cin >> a;
int x; cin >> x;
if (a == 'I')
arr.insert(x);
else {
if (arr.empty())
continue;
if (x == 1) {
auto iter = arr.end();
iter--;
arr.erase(iter);
}
else {
auto iter = arr.begin();
arr.erase(iter);
}
}
}
if (arr.empty())
cout << "EMPTY" << "\n";
else {
auto end = arr.end();
end--;
cout << *end << " " << *arr.begin() << "\n";
}
}
return 0;
}