-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBerpizza.cpp
More file actions
43 lines (41 loc) · 1005 Bytes
/
Berpizza.cpp
File metadata and controls
43 lines (41 loc) · 1005 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x,cst=1;
cin>>n;
set<int> current;
set<pair<int,int>> st;
map<int,int> hash;
for(int i=0; i<n; i++)
{
int m;
cin>>x;
if(x==1)
{
cin>>m;
hash[cst]=m;
current.insert(cst);
st.insert({m,-cst});
cst++;
}
else if(x==2)
{
int toremove = *(current.begin());
current.erase(toremove);
st.erase(make_pair(hash[toremove], -toremove));
cout<<toremove<<" ";
}
else if(x==3)
{
pair<int,int> pr = *(st.rbegin());
// pr->first = maximum tip
// pr->second = negative of the customer number
int cst_num = -(pr.second);
current.erase(cst_num);
st.erase(pr);
cout<<-(pr.second)<<" ";
}
}
return 0;
}