-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7662.cpp
More file actions
53 lines (48 loc) · 1.33 KB
/
7662.cpp
File metadata and controls
53 lines (48 loc) · 1.33 KB
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
49
50
51
52
53
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int T,k,n=0;
cin>>T;
for(int t=0;t<T;t++){
priority_queue<int,vector<int>,greater<int>> lpq;
priority_queue<int> gpq;
map<int,int> nums;
cin>>k;
char c;
for(int i=0;i<k;i++){
cin>>c>>n;
if(c=='I'){
nums[n]++;
lpq.push(n);
gpq.push(n);
}else{
if(n==1){
while(!gpq.empty()&&nums[gpq.top()]==0) gpq.pop();
if(!gpq.empty()){
nums[gpq.top()]--;
gpq.pop();
}
}
else{
while(!lpq.empty()&&nums[lpq.top()]==0) lpq.pop();
if(!lpq.empty()){
nums[lpq.top()]--;
lpq.pop();
}
}
}
}
while(!gpq.empty()&&nums[gpq.top()]==0) gpq.pop();
while(!lpq.empty()&&nums[lpq.top()]==0) lpq.pop();
if(gpq.empty()||lpq.empty()) cout<<"EMPTY\n";
else cout<<gpq.top()<<' '<<lpq.top()<<'\n';
}
return 0;
}