fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static List<int> getMax(List<string> operations)
  6. {
  7. Stack<int> arr = new Stack<int>();
  8. List<int> ans = new List<int>();
  9.  
  10. SortedDictionary<int, int> occurences = new SortedDictionary<int, int>();
  11.  
  12. foreach (var query in operations)
  13. {
  14. if (query.Length > 1)
  15. {
  16. string x = query.Substring(2);
  17. int value = int.Parse(x);
  18.  
  19. arr.Push(value);
  20.  
  21. if (occurences.ContainsKey(value))
  22. {
  23. occurences[value]++;
  24. }
  25. else
  26. {
  27. occurences.Add(value, 1);
  28. }
  29. }
  30. else if (query == "2")
  31. {
  32. occurences[arr.Peek()]--;
  33.  
  34. if (occurences[arr.Peek()] == 0)
  35. {
  36. occurences.Remove(arr.Peek());
  37. }
  38.  
  39. arr.Pop();
  40. }
  41. else
  42. {
  43. ans.Add(occurences.Last().Key);
  44. }
  45. }
  46.  
  47. return ans;
  48. }
  49.  
  50. public static void Main()
  51. {
  52. // your code goes here
  53. }
  54. }
  55.  
Success #stdin #stdout 0.04s 21724KB
stdin
Standard input is empty
stdout
Standard output is empty