forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
48 lines (43 loc) · 1.21 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/3a213ad379ca457c87e01e73a8ddf8b2
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while(t--) {
map<int, int> mp;
int n; cin >> n;
for(int i=0;i<n;i++) {
char cmd; cin >> cmd;
int x;cin >> x;
if(cmd == 'I') {
mp[x] += 1;
}
else {
if(mp.empty()) continue;
if(x == -1) {
if(mp.begin()->second == 1) {
mp.erase(mp.begin()->first);
}
else {
mp.begin()->second --;
}
}
else {
if(mp.rbegin()->second == 1) {
mp.erase(mp.rbegin()->first);
}
else {
mp.rbegin()->second --;
}
}
}
}
if(mp.empty()) cout << "EMPTY\n";
else cout << mp.rbegin()->first << ' ' << mp.begin()->first << '\n';
}
return 0;
}