Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <memory.h>
- #include <stdlib.h>
- #include <iostream>
- #include <time.h>
- #include <algorithm>
- #include <math.h>
- #include <vector>
- #include <set>
- #include <queue>
- #include <stack>
- #include <bitset>
- #include <string>
- #include <cstring>
- #include <cassert>
- #include <fstream>
- #include <map>
- #include <unordered_map>
- #include <deque>
- #include <unordered_set>
- using namespace std;
- int n;
- map <string, int> used;
- vector <pair <string, int>> arr;
- int main() {
- srand(time(0));
- cin >> n;
- for (int i = 0; i < n; i++) {
- string type;
- cin >> type;
- if (type == "add") {
- int x;
- string name;
- cin >> x >> name;
- used[name] += x;
- if (arr.size() && arr.back().first == name) {
- arr.back().second += x;
- }
- else {
- arr.push_back({ name, x });
- }
- }
- else if (type == "delete") {
- int x;
- cin >> x;
- for (; x > 0;) {
- if (arr.back().second <= x) {
- x -= arr.back().second;
- used[arr.back().first] -= arr.back().second;
- arr.pop_back();
- }
- else {
- used[arr.back().first] -= x;
- arr.back().second -= x;
- x = 0;
- }
- }
- }
- else {
- string name;
- cin >> name;
- if (!used.count(name)) {
- cout << "0\n";
- }
- else {
- cout << used[name] << "\n";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement