cswork / OAOpen practice workspace

ReevoOA #3

Exit Time with Elastic Collisions

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)Bits & MathIn-place Arrays

Objects are moving along a table of length tableLength. The position of the i-th object is given by position[i], when 0 <= position[i] < tableLength. The left end of the line is at coordinate 0, and the right end is at coordinate tableLength. A positive velocity means moving towards the right end, and a negative velocity means moving towards the left end.

When two objects collide, their velocities are exchanged. Objects are removed if they move left of coordinate 0 or right of coordinate tableLength. All objects keep moving simultaneously at time 0.

Your task is to find the time in seconds when the last object exits the line. The answer should be rounded to the nearest integer (ceiling).

Editorial

Loading solution…