Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, x;
- string h, f;
- unordered_map <string, long long> u;
- vector <pair <int, string>> ara;
- int main()
- {
- iostream::sync_with_stdio(0); cin.tie(0);
- cin >> n;
- for (int xx = 0 ; xx < n ; xx++)
- {
- cin >> h;
- if (h == "add")
- {
- cin >> x >> f;
- ara.push_back({x, f});
- u[f] += x;
- }
- else if (h == "delete")
- {
- cin >> x;
- while (ara.size() > 0 && (ara.back()).first <= x)
- {
- x -= (ara.back()).first;
- u[(ara.back()).second] -= (ara.back()).first;
- ara.pop_back();
- }
- if (ara.size() == 0)
- continue;
- (ara.back()).first -= x;
- u[(ara.back()).second] -= x;
- }
- else
- {
- cin >> f;
- cout << u[f] << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement