728x90
#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;
}
'백준' 카테고리의 다른 글
쿼드트리-1992번 (Java) (0) | 2021.08.22 |
---|---|
Z - 1074번 (Java) (0) | 2021.08.22 |
찾기 - KMP 알고리즘 (0) | 2021.04.02 |
인구이동 (0) | 2021.01.25 |