THEPOOL - The One-Dimensional Pool Table
A set of N billiard balls are set on a one-dimensional table. The table is 105 meters long, with two pockets at either side. Each ball has zero width and there is no friction so it is moving with a fixed velocity of either left or right and bounces back in a perfect elastic collision from other balls it encounter on its way (or drop into one of the pockets). Your job is to keep track of the balls' movements.
The first number, N, is the number of balls (<= 105).
This is followed by N pairs of numbers: the distance in meters from the left end of the table and the velocity (positive speed meaning it moves towards right).
The next line tells you which ball you have to track ( 1 <= tracked ball <= N).
The last line tells you the time T at which you have to locate the tracked ball.
Note: Each number is on a separate line.
You have to output the position (from the left end) of the tracked ball after time T.
6 Output: 56
2 is the number of balls,
One ball is placed at 95 from the left end. It's velocity is -1 (i.e. 1 m/s towards left).
Another ball is at distance 10. Velocity is 1 (i.e. towards right).
The first ball from left end is to be tracked. (i.e. ball at distance 10 from left end).
You need to find the new position of the tracked ball at time t=60s.