Rounding
Time limit2sMemory limit512 MB
Given rounded integer percentages from 10000 respondents, find the possible range of each place's true percentage, or report IMPOSSIBLE if no consistent assignment exists.
- Level
Medium6 of 10
- Topics
- Math, Implementation, Greedy, Binary search
- Solved
- No attempts yet
Problem

You decided to stay an extra day in Paris and visit the places Parisians around Télécom ParisTech like most. You want to collect information about these places, but asking people to fill in surveys is less fun than coding. So you asked the Parisian Agency for Really Imprecise Surveys to do it for you. You sent them a list of the P places you were interested in.
After surveying exactly 10 000 persons and asking them their favorite place among these P places, the agency has just sent you the results. All persons surveyed answered the question. Unfortunately, the agency rounded the percentage results to the nearest integer with the formula result = original_value + 1/2. In particular, decimal values of .50 are rounded up.
But since 10 000 persons were surveyed, you should have been able to get percentage values precise to the second decimal. What a loss of precision! You want to know the range in which each original result could have been.
Input
The input comprises several lines:
- The first line consists of an integer P.
- Each of the following P lines consists of the name of a place followed by an integer i, separated with a single space.
Output
If the results given by the agency are not consistent, print a single line with the word IMPOSSIBLE. Otherwise the output should consist of P lines. Each of them consists of the name of a place followed by a single space and two numbers, the smallest and the largest percentage values that place could have had in the original results, as floating-point numbers with two decimals separated with a single space. Each number must have at least one digit before the decimal point, even if it is 0, and exactly 2 decimals, even if the trailing ones are 0. The places must be in the same order as in the input.
Constraints
- 1 ≤ P ≤ 10 000;
- the name of a place is a string of between 1 and 20 characters among Latin alphabet letters (‘A’ to ‘Z’ and ‘a’ to ‘z’) and the underscore character (‘_’);
- no two names are the same;
- 0 ≤ i ≤ 100.