Advertisement
Georgiy1108

Untitled

Nov 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. map<string, long long> mp;
  6. vector<pair<long long, string>> a;
  7.  
  8. void del(long long k)
  9. {
  10.     while(k > 0)
  11.     {
  12.         long long t = min(k, a.back().first);
  13.         k -= t;
  14.         a.back().first -= t;
  15.         mp[a.back().second] -= t;
  16.         if(a.back().first == 0)
  17.             a.pop_back();
  18.     }
  19. }
  20.  
  21. main()
  22. {
  23.     ios::sync_with_stdio(0);
  24.     cin.tie(0);
  25.     long long n;
  26.     cin >> n;
  27.     while(n--)
  28.     {
  29.         string cmd;
  30.         cin >> cmd;
  31.         if(cmd == "get")
  32.         {
  33.             string c;
  34.             cin >> c;
  35.             cout << mp[c] << "\n";
  36.         }
  37.         else if(cmd == "add")
  38.         {
  39.             long long k;
  40.             string c;
  41.             cin >> k >> c;
  42.             a.push_back({k, c});
  43.             mp[c] += k;
  44.         }
  45.         else
  46.         {
  47.             long long k;
  48.             cin >> k;
  49.             del(k);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement