fork(2) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, dem = 0, top;
  6. priority_queue <int > t;
  7.  
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(0), cin.tie(0);
  11. //freopen("inp.txt", "r", stdin);
  12. cin >> n;
  13. for (int i = 1; i <= 2*n; i++)
  14. {
  15. string s;
  16. cin >> s;
  17. if (s == "add")
  18. {
  19. cin >> top;
  20. t.push(-top);
  21. } else
  22. {
  23. if (t.empty()) continue;
  24. if (top == -t.top())
  25. {
  26. t.pop();
  27. top = -t.top();
  28. }
  29. else
  30. {
  31. dem ++;
  32. t.pop();
  33. top = -t.top();
  34. }
  35. }
  36. }
  37. cout << dem;
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty