fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ar array
  6. #define vt vector
  7.  
  8. const int mxN=5e5;
  9. string str;
  10. int t, n, ma=0, mi=mxN;
  11.  
  12. int main() {
  13. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  14. cin >> n;
  15. stack<int> minus;
  16. while(n--) {
  17. cin >> str;
  18. if(str=="PUSH") {
  19. cin >> t;
  20. if(minus.empty())
  21. minus.push(t);
  22. else
  23. minus.push(min(minus.top(), t));
  24. }
  25. else if(str=="POP") {
  26. if(minus.empty())
  27. cout << "EMPTY\n";
  28. else
  29. minus.pop();
  30. }
  31. else {
  32. if(minus.empty())
  33. cout << "EMPTY\n";
  34. else
  35. cout << minus.top() << "\n";
  36. }
  37. }
  38. }
  39.  
Success #stdin #stdout 0s 548KB
stdin
Standard input is empty
stdout
Standard output is empty