Racetrack
Time limit2sMemory limit512 MB
Given ordered lap times and lap counts and the rule that passes happen only at the finish line, compute when each runner finishes the race.
- Level
Hard8 of 10
- Topics
- Simulation, Implementation, Sorting, Math
- Solved
- No attempts yet
Problem

On a circular racetrack, players run a fixed number of laps. Every player has her own maximum speed. Player needs units of time for one lap at maximum speed and has to complete laps.
On this track a player can pass another player only at the finish line. When a player catches up with a slower player during a lap, she stays right behind him until the end of that lap, so the two cross the finish line at the same moment.
Every player who crosses the finish line at the same moment starts again from there at her own maximum speed, so faster players move ahead of slower ones.
At the start all players stand together at the finish line. A player who completes her last lap leaves the track at once and blocks nobody after that.
Given the lap time and the number of laps of every player, compute the moment each player completes the race.
Input
The first line contains the number of players ().
Each of the next lines describes one player: the -th of them contains the lap time and the number of laps of player (, ).
The players are given in order of decreasing speed, that is .
Output
Print lines. The -th line contains the moment player completes the race.