E. Rounding

Codeforces
IDCF10246E
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You decided to stay an extra day in Paris visiting favorite places of Parisians around T'el'ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in surveys is less fun than coding. For this reason, 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, using the following formula: $r e s u l t = floor.l o r i g i n a l_v a l u e + frac(1, 2) floor.r$. In particular, decimal values of $. 50$ are rounded up. But since $10000$ 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 be. The input comprises several lines: *Limits* 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 should consist 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. ## 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. *Limits* $1 <= P <= 10000$; 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$. ## 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 should consist 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. [samples]
**Definitions** Let $ P \in \mathbb{Z}^+ $ be the number of places. Let $ R = (r_1, r_2, \dots, r_P) $ be the rounded percentages (integers) reported by the agency, where $ r_i \in \{0, 1, \dots, 100\} $. Let $ x_i \in \mathbb{R} $ be the true percentage for place $ i $, such that $ x_i \in [0, 100] $ and $ \sum_{i=1}^P x_i = 100 $. Let $ n = 10000 $ be the number of respondents. The true count for place $ i $ is $ c_i = \frac{x_i}{100} \cdot n $, so $ c_i \in [0, 10000] $ and $ \sum_{i=1}^P c_i = 10000 $. Rounding rule: $ r_i = \left\lfloor x_i + \frac{1}{2} \right\rfloor $, i.e., $ r_i - 0.5 \leq x_i < r_i + 0.5 $. **Constraints** 1. $ \sum_{i=1}^P r_i \in \{99, 100, 101\} $ (necessary for consistency, since rounding may shift total by at most $ P \cdot 0.5 $, but total must be 100). 2. For each $ i \in \{1, \dots, P\} $: $$ r_i - 0.5 \leq x_i < r_i + 0.5 $$ 3. $ \sum_{i=1}^P x_i = 100 $ 4. $ x_i \geq 0 $ for all $ i $, and $ x_i \leq 100 $ for all $ i $ **Objective** If no $ (x_1, \dots, x_P) $ satisfies constraints, output "IMPOSSIBLE". Otherwise, for each place $ i $, compute: - Minimum possible $ x_i $: $ \max\left(r_i - 0.5, \; 100 - \sum_{j \ne i} (r_j + 0.5 - \epsilon)\right) $ - Maximum possible $ x_i $: $ \min\left(r_i + 0.5 - \epsilon, \; 100 - \sum_{j \ne i} (r_j - 0.5)\right) $ Formally, for each $ i $: $$ \text{min}_i = \max\left( r_i - 0.5, \; 100 - \sum_{j \ne i} (r_j + 0.5) \right) $$ $$ \text{max}_i = \min\left( r_i + 0.5, \; 100 - \sum_{j \ne i} (r_j - 0.5) \right) $$ with the understanding that $ \text{min}_i \leq \text{max}_i $ must hold for feasibility. Output $ \text{min}_i $ and $ \text{max}_i $ as floating-point numbers with exactly two decimal digits.
API Response (JSON)
{
  "problem": {
    "name": "E. Rounding",
    "description": {
      "content": "You decided to stay an extra day in Paris visiting favorite places of Parisians around T'el'ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in su",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10246E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You decided to stay an extra day in Paris visiting favorite places of Parisians around T'el'ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in su...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ P \\in \\mathbb{Z}^+ $ be the number of places.  \nLet $ R = (r_1, r_2, \\dots, r_P) $ be the rounded percentages (integers) reported by the agency, where $ r_i \\in \\{0, 1, \\dots, ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments