Advertisement
LEGEND2004

Minimum in the stack

Feb 12th, 2023
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n , option , x;
  6.     cin >> n;
  7.     stack<int> s;
  8.     multiset<int> m;
  9.     while(n--){
  10.         cin >> option;
  11.         if(option == 1){
  12.             cin >> x;
  13.             s.push(x);
  14.             m.insert(x);
  15.             continue;
  16.         }
  17.         if(option == 2){
  18.             m.erase(m.find(s.top()));
  19.             s.pop();
  20.             continue;
  21.         }
  22.         cout << *(m.begin()) << '\n';
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement