Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Problem 3. Maximum and Minimum Element
  2. You have an empty sequence, and you will be given N queries. Each query is one of these three types:
  3. 1 x – Push the element x into the stack.
  4. 2 – Delete the element present at the top of the stack.
  5. 3 – Print the maximum element in the stack.
  6. 4 – Print the minimum element in the stack.
  7. After you go through all of the queries, print the stack in the following format:
  8. "{n}, {n1}, {n2}….., {nn}"
  9. Input
  10. • The first line of input contains an integer, N
  11. • The next N lines each contain an above-mentioned query. (It is guaranteed that each query is valid.)
  12. Output
  13. • For each type 3 or 4 query, print the maximum/minimum element in the stack on a new line
  14. Constraints
  15. • 1 ≤ N ≤ 105
  16. • 1 ≤ x ≤ 109
  17. • 1 ≤ type ≤ 4
  18.  
  19. Examples
  20. Input
  21. 9
  22. 1 97
  23. 2
  24. 1 20
  25. 2
  26. 1 26
  27. 1 20
  28. 3
  29. 1 91
  30. 3
  31. Output
  32. 26
  33. 20
  34. 91, 20, 26
  35.  
  36. Input
  37. 10
  38. 2
  39. 1 47
  40. 1 66
  41. 1 32
  42. 4
  43. 3
  44. 1 25
  45. 1 16
  46. 1 8
  47. 4
  48. Output
  49. 32
  50. 66
  51. 8
  52. 8, 16, 25, 32, 66, 47
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement