100 atcoder#ABC128E. [ABC128E] Roadwork
[ABC128E] Roadwork
Score : points
Problem Statement
There is an infinitely long street that runs west to east, which we consider as a number line.
There are roadworks scheduled on this street. The -th roadwork blocks the point at coordinate from time to time .
people are standing at coordinate . The -th person will start the coordinate at time , continue to walk with speed in the positive direction and stop walking when reaching a blocked point.
Find the distance each of the people will walk.
Constraints
- All values in input are integers.
- If and , the intervals and do not overlap.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the distance the -th person will walk or if that person walks forever.
4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8
2
2
10
-1
13
-1
The first person starts coordinate at time and stops walking at coordinate when reaching a point blocked by the first roadwork at time .
The second person starts coordinate at time and reaches coordinate at time . The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate .
The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is .