Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- train = []
- counts = dict()
- def push(cnt, name):
- counts[name] = counts.get(name, 0) + cnt
- if len(train) > 0 and train[-1][0] == name:
- train[-1][1] += cnt
- else:
- train.append( [name, cnt] )
- def pop(t):
- while train[-1][1] < t:
- t -= train[-1][1]
- counts[train[-1][0]] -= train[-1][1]
- train.pop()
- train[-1][1] -= t
- counts[train[-1][0]] -= t
- n = int(input())
- for i in range(n):
- lst = input().split()
- if lst[0] == 'add':
- cmd, cnt, loot = lst
- cnt = int(cnt)
- push( cnt, loot )
- elif lst[0] == 'delete':
- cmd, cnt = lst
- cnt = int(cnt)
- pop(cnt)
- else:
- cmd, loot = lst
- print( counts.get(loot, 0) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement