Elastic collisions

0.60

You have a billiard pool L units long and 1 unit wide, and n identical
billiard balls of diameter 1, labeled from left to right with the
numbers 1, 2, …, n. Initially, all balls are at integer positions, and
the ball 1 is at the very left (at the position 1). After striking the
ball 1, it moves to the right, with a speed of 1 unit per second.
Supposing that the collisions (between the balls as well as against
right and left walls) are completely elastic, and that there is no
friction, at which position will a given ball be at a given second?

  0.40

(140,170) (13.5,155)1 (25.5,155)2 (37.5,155)3 (49.5,155)4 (61.5,155)5
(73.5,155)6 (85.5,155)7 (97.5,155)8 (109.5,155)9 (121.5,155)10
(133.5,155)11

(9,151)(1,0)134 (9,136)(1,0)134 (9,131)(1,0)134 (9,116)(1,0)134
(9,111)(1,0)134 (9,96)(1,0)134 (9,91)(1,0)134 (9,76)(1,0)134
(9,71)(1,0)134 (9,56)(1,0)134 (9,51)(1,0)134 (9,36)(1,0)134
(9,31)(1,0)134 (9,16)(1,0)134 (9,11)(1,0)134 (9,-4)(1,0)134

(9,151)(0,-1)15 (9,131)(0,-1)15 (9,111)(0,-1)15 (9,91)(0,-1)15
(9,71)(0,-1)15 (9,51)(0,-1)15 (9,31)(0,-1)15 (9,11)(0,-1)15

(143,151)(0,-1)15 (143,131)(0,-1)15 (143,111)(0,-1)15 (143,91)(0,-1)15
(143,71)(0,-1)15 (143,51)(0,-1)15 (143,31)(0,-1)15 (143,11)(0,-1)15

(2,143.5)(1,0)8 (14,123.5)(1,0)8 (26,103.5)(1,0)8 (50,83.5)(1,0)8
(86,63.5)(1,0)8 (98,43.5)(1,0)8 (122,23.5)(1,0)8 (138,3.5)(-1,0)8

(16,143.5)(13.5,140)1 (52,143.5)(49.5,140)2 (76,143.5)(73.5,140)3
(88,143.5)(85.5,140)4 (124,143.5)(121.5,140)5

(28,123.5)(25.5,120)1 (52,123.5)(49.5,120)2 (76,123.5)(73.5,120)3
(88,123.5)(85.5,120)4 (124,123.5)(121.5,120)5

(40,103.5)(37.5,100)1 (52,103.5)(49.5,100)2 (76,103.5)(73.5,100)3
(88,103.5)(85.5,100)4 (124,103.5)(121.5,100)5

(40,83.5)(37.5,80)1 (64,83.5)(61.5,80)2 (76,83.5)(73.5,80)3
(88,83.5)(85.5,80)4 (124,83.5)(121.5,80)5

(40,63.5)(37.5,60)1 (64,63.5)(61.5,60)2 (76,63.5)(73.5,60)3
(100,63.5)(97.5,60)4 (124,63.5)(121.5,60)5

(40,43.5)(37.5,40)1 (64,43.5)(61.5,40)2 (76,43.5)(73.5,40)3
(112,43.5)(109.5,40)4 (124,43.5)(121.5,40)5

(40,23.5)(37.5,20)1 (64,23.5)(61.5,20)2 (76,23.5)(73.5,20)3
(112,23.5)(109.5,20)4 (136,23.5)(133.5,20)5

(40,3.5)(37.5,0)1 (64,3.5)(61.5,0)2 (76,3.5)(73.5,0)3
(112,3.5)(109.5,0)4 (124,3.5)(121.5,0)5

Input

Input consists of several cases. Each case begins with L and n, followed
by the n positions of the balls. All the positions are different,
between 1 and L, and one of them is 1. Then comes q ≥ 1, the number of
queries about this case, followed by q pairs of integer numbers i and t.
Assume 1 ≤ n ≤ 10⁴, n < L ≤ 10⁶, 1 ≤ i ≤ n, and 0 ≤ t ≤ 10⁸.

Output

For each pair of i and t, print the position of the ball with label i at
the second t, following the format of the example. Print an empty line
after the output for each case.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:11:54.820Z

© Jutge.org, 2006–2026.
https://jutge.org
