Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- map<string, long long> mp;
- vector<pair<long long, string>> a;
- void del(long long k)
- {
- while(k > 0)
- {
- long long t = min(k, a.back().first);
- k -= t;
- a.back().first -= t;
- mp[a.back().second] -= t;
- if(a.back().first == 0)
- a.pop_back();
- }
- }
- main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- long long n;
- cin >> n;
- while(n--)
- {
- string cmd;
- cin >> cmd;
- if(cmd == "get")
- {
- string c;
- cin >> c;
- cout << mp[c] << "\n";
- }
- else if(cmd == "add")
- {
- long long k;
- string c;
- cin >> k >> c;
- a.push_back({k, c});
- mp[c] += k;
- }
- else
- {
- long long k;
- cin >> k;
- del(k);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement