Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, x;
  6. string h, f;
  7. unordered_map <string, long long> u;
  8. vector <pair <int, string>> ara;
  9.  
  10. int main()
  11. {
  12. iostream::sync_with_stdio(0); cin.tie(0);
  13. cin >> n;
  14. for (int xx = 0 ; xx < n ; xx++)
  15. {
  16. cin >> h;
  17. if (h == "add")
  18. {
  19. cin >> x >> f;
  20. ara.push_back({x, f});
  21. u[f] += x;
  22. }
  23. else if (h == "delete")
  24. {
  25. cin >> x;
  26. while (ara.size() > 0 && (ara.back()).first <= x)
  27. {
  28. x -= (ara.back()).first;
  29. u[(ara.back()).second] -= (ara.back()).first;
  30. ara.pop_back();
  31. }
  32. if (ara.size() == 0)
  33. continue;
  34. (ara.back()).first -= x;
  35. u[(ara.back()).second] -= x;
  36. }
  37. else
  38. {
  39. cin >> f;
  40. cout << u[f] << "\n";
  41. }
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement