fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6.  
  7. int main() {
  8. ios::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. cout.tie(NULL);
  11. int t;
  12. cin >> t;
  13. queue < int > q;
  14. priority_queue < int ,vector<int> , greater<> > pq;
  15. while (t--) {
  16. int opt;
  17. cin >> opt;
  18. if (opt == 1) {
  19. int x;
  20. cin >> x;
  21. q.push(x);
  22. }
  23. else if (opt == 2) {
  24. if (!pq.empty()) {
  25. cout << pq.top() << endl;
  26. pq.pop();
  27.  
  28. }
  29. else if (!q.empty()) {
  30. cout << q.front() << endl;
  31. q.pop();
  32. }
  33. }
  34. else if (opt == 3) {
  35. while (!q.empty()) {
  36. pq.push(q.front());
  37. q.pop();
  38. }
  39. }
  40. }
  41.  
  42. }
  43.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty