#P6013. Little Z's Money Shortage Problem
Little Z's Money Shortage Problem
Little Z's Money Shortage Problem
Little Z faces a sequence of m events. There are three types of events:
- Type 1: Little Z receives a yuan. (i.e. his available money increases by a.)
- Type 2: Little Z tries to spend a yuan to buy a skin. If his available money is less than a, he becomes unhappy and does not spend any money.
- Type 3: Little Z seals a yuan of his money. The sealed money will be released exactly 1 second before the b-th event occurs. It is guaranteed that at the moment of sealing, his available money is at least a.
Before processing every event, check if any sealed money is scheduled to be released (i.e. if the current event index matches any release time). Released money is added back to his available money. Process the event afterward.
Your task is to count the number of events in which Little Z becomes unhappy (i.e. the spend events where his available money is insufficient).
For any formulas, use LaTeX format. For example, the amount is given as $a$, and the event index as $b$.
inputFormat
The first line contains an integer m
($1 \le m \le 10^5$) representing the number of events. Each of the following m
lines describes an event in one of the following formats:
- For Type 1 and Type 2 events:
t a
, wheret
is either 1 or 2, anda
($1 \le a \le 10^9$) denotes the amount. - For a Type 3 event:
3 a b
, wherea
($1 \le a \le 10^9$) is the sealed amount andb
($1 \le b \le m$) is the event index at which the money will be released (release occurs just before processing theb
-th event). It is guaranteed thatb
is greater than the current event index and that at the moment of sealing, available money is at leasta
.
outputFormat
Output a single integer representing the number of events in which Little Z becomes unhappy because he does not have enough available money for a spending (Type 2) event.
sample
5
1 100
2 50
3 30 5
2 80
2 30
1