Magic Rods
InterviewTime limit2sMemory limit1024 MB
Choose positive integer ignition times at both ends of each rod so that every rod's last point is lit at distance d_i and all rods finish at the same earliest moment.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Statement
Bella has numbered magic rods. To get magic energy, Bella lights each rod at both ends, possibly at different moments. The fire spreads at one centimeter per second. The energy of a rod is released at the moment the fire covers the whole rod.
The length of rod is centimeters. Help Bella choose the ignition times of the ends of each rod so that the energy of all rods is released at the same moment. Bella also wants the last point of rod to catch fire at distance from the first end of that rod.
All ignition times must be positive integers. Among all valid answers, choose the one that minimizes the moment when all the energy is released.
Input
The first line contains one integer (), the number of rods. Each of the next lines contains two integers and (, ): the length of rod and the distance from its first end to the point that must be lit last.
Output
On the -th line, print two positive integers and : the moments to ignite the first and the second end of rod .