-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestaurant_rating.cpp
53 lines (40 loc) · 1.04 KB
/
restaurant_rating.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
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char const *argv[])
{
priority_queue<ll> low;
priority_queue<ll, vector<ll>, greater<ll>> high;
ll qtd, cmd, total = 0;
cin >> qtd;
while(qtd--){
cin >> cmd;
switch (cmd)
{
case 1:
ll aux;
cin >> aux;
low.push(aux);
total++;
if(high.size() < total/3){
high.push(low.top());
low.pop();
}
while(!high.empty() and low.top() > high.top()){
auto next = low.top();
auto prev = high.top();
low.pop();
high.pop();
low.push(prev);
high.push(next);
}
break;
default:
if (!high.empty())
cout << high.top() << endl;
else
cout << "No reviews yet" << endl;
}
}
return 0;
}