100 atcoder#ABC217D. [ABC217D] Cutting Woods
[ABC217D] Cutting Woods
Score : points
Problem Statement
We have a long piece of timber with a length of meters. For each , there is a mark called Mark at meters from the left end of the piece.
You are given queries, the -th of which is represented as a pair of numbers . Process the queries in ascending order of as described below.
- If : cut the piece at Mark into two.
- If : choose the piece with Mark on it and print its length.
Here, for both kinds of queries , it is guaranteed that there will have been no cut at Mark when the query is to be processed.
Constraints
- For every , the following holds: there is no such that and .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of lines equal to the number of queries . In the -th line, print the response to the -th such query.
5 3
2 2
1 3
2 2
5
3
At the time of the first query, no cut has been made, so the piece with Mark has a length of meters. Thus, you should print . In the second query, the piece is cut into two pieces with lengths of and meters. At the time of the third query, the piece with Mark has a length of meters, so you should print .
5 3
1 2
1 4
2 3
2
100 10
1 31
2 41
1 59
2 26
1 53
2 58
1 97
2 93
1 23
2 84
69
31
6
38
38