Beads
Time limit2sMemory limit512 MB
Beads of equal mass collide elastically on a line; find the position of the one marked red after t seconds.
- Level
Medium6 of 10
- Topics
- Sorting, Simulation, Math
- Solved
- No attempts yet
Problem
Minjun runs a bead experiment on a frictionless number line of infinite length. There are beads. Each bead has negligible size, and all beads have the same mass. When two beads hit each other, the collision is perfectly elastic.
Minjun painted exactly one bead red. At time , bead is at position and starts moving with initial velocity . A bead changes its velocity only when it collides with another bead.
Find the position of the red bead after seconds.
Input
The first line contains the number of beads and the time . (, )
Each of the next lines contains the position and the initial velocity of bead . ()
The red bead is the one given first in the input. A negative means the bead moves in the direction.
All given numbers are integers, and the bead positions are distinct.
Output
Print the position of the red bead after seconds. This value is guaranteed to be an integer.
Hint
A perfectly elastic collision conserves both momentum and kinetic energy. When two beads of equal mass collide perfectly elastically, they exchange velocities.
In the sample input the red bead hits bead 2 at time , bead 4 at time , bead 2 again at time , and bead 4 again at time . At time it is at position .