Binary Scale
InterviewTime limit1sMemory limit128 MB
Sort the given (reading, precision) pairs by reading divided by 2 to the precision, breaking ties by smaller reading.
- Level
Easy3 of 10
- Topics
- Sorting
- Solved
- No attempts yet
Problem
A binary scale is a special device that can measure any value in the open interval with a fixed precision. The precision is set with a dial that can be turned to . When the precision is set to , the scale measures in units of .
A measurement is recorded as a pair . Such a pair means the precision is set to and the scale reads , so the weight of the measured object is . Here is a positive integer, and since the scale only reads values in we have .
Write a program that orders the measurements from the smallest value to the largest. Each measurement is given as a pair . Different pairs that represent the same value (for example and , both equal to ) must be ordered by increasing reading , the first element of the pair.
Input
The program reads from standard input. The first line contains an integer (), the number of pairs. Each of the next lines contains one pair and , separated by a single space. For every pair, and .
Output
The program writes to standard output. Output the input pairs, reordered so that pairs with smaller measured values come before pairs with larger measured values. Pairs with equal measured values are printed in non-decreasing order of their reading . Print each pair in the same format as the input, that is, the two integers and separated by a single space.