Echo Chase
During a live set, a DJ uses an echo pedal that replays a note by jumping forward in time. The song is split into notes. Note
lasts for
milliseconds. Its start time is
The pedal is configured with a delay for each note. If the pedal triggers on note
, it jumps to the first note whose start time is strictly greater than
. If no such note exists, the pedal lands in silence, and all further jumps stay in silence.
You are given many queries. Each query gives a starting note and a number of jumps
. For each query, output the note index where the echo lands after exactly
jumps, or
if it ends in silence.
Input
The first line contains two integers and
(
), the number of notes and the number of queries.
The next lines each contain two integers
and
(
), the duration and echo delay for each note.
The next lines each contain two integers
and
(
,
), the starting note and number of jumps for each query.
Output
For each query, print a single integer: the note index after jumps, or
if the echo is in silence.
Notes
Try selecting PyPy3 for your Python submissions for a free speed boost!
Examples
Input 1
5 5
3 4
2 3
4 1
1 7
5 2
1 1
1 2
1 3
2 1
3 2
Output 1
3
4
0
4
0
The start times are .
- From note 1,
, so the next note is 3.
- From note 1, two jumps go
.
- From note 1, three jumps go
.
Input 2
1 4
5 10
1 0
1 1
1 2
1 10
Output 2
1
0
0
0
The only note starts at time 0. Any positive jump exceeds all note start times, so the echo goes to silence.
Input 3
3 5
3 3
3 1
3 1
1 1
1 2
2 1
2 2
3 1
Output 3
3
0
3
0
0
The start times are . From note 1,
hits time
exactly, so the next note is
(strictly greater than
).
Comments