-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Berpizza.cpp
More file actions
55 lines (47 loc) · 1.41 KB
/
C_Berpizza.cpp
File metadata and controls
55 lines (47 loc) · 1.41 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
54
55
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
void solve() {
int q;
cin >> q;
queue<int> arrivalQueue; //waiter 1 FIFO queue
priority_queue<pii> maxHeap; //waiter 2 max-heap (money, -customerID)
unordered_set<int> served; // served customers
int customerID = 1;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int m;
cin >> m;
arrivalQueue.push(customerID);
maxHeap.push({m, -customerID}); // Store negative ID for tiebreaker
customerID++;
}
else if (type == 2) {
while (!arrivalQueue.empty() && served.count(arrivalQueue.front())) {
arrivalQueue.pop(); // Skip already served customers
}
int servedID = arrivalQueue.front();
arrivalQueue.pop();
served.insert(servedID);
cout << servedID << " ";
}
else if (type == 3) {
while (!maxHeap.empty() && served.count(-maxHeap.top().second)) {
maxHeap.pop(); // Skip already served customers
}
int servedID = -maxHeap.top().second;
maxHeap.pop();
served.insert(servedID);
cout << servedID << " ";
}
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
solve();
}