E. Numbers on Whiteboard

Codeforces
IDCF10279E
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Numbers $1, 2, 3, \\dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $frac(a + b, 2)$ _rounded up_ instead. You should perform the given operation $n -1$ times and make the resulting number that will be left on the board as small as possible. It's easy to see that after $n -1$ operations, there will be left only one number. Your goal is to minimize it. The first line contains one integer $n$ ($2 <= n <= 2 dot.op 10^5$) — the number of integers written on the board initially. In the first line, print the minimum possible number left on the board after $n -1$ operations. Each of the next $n -1$ lines should contain two integers — numbers $a$ and $b$ chosen and erased in each operation. In the first sample, numbers $[ 1, 2, 3, 4 ]$ are written on the board initially. In the first operation, numbers $2$ and $4$ are erased and number $3$ are written instead. So, after the first operation, the numbers $[ 1, 3, 3 ]$ will be written. After the second operation, the numbers $[ 1, 3 ]$ will be written. Finally, after the third operation, the only number left is $2$. ## Input The first line contains one integer $n$ ($2 <= n <= 2 dot.op 10^5$) — the number of integers written on the board initially. ## Output In the first line, print the minimum possible number left on the board after $n -1$ operations. Each of the next $n -1$ lines should contain two integers — numbers $a$ and $b$ chosen and erased in each operation. [samples] ## Note In the first sample, numbers $[ 1, 2, 3, 4 ]$ are written on the board initially. In the first operation, numbers $2$ and $4$ are erased and number $3$ are written instead. So, after the first operation, the numbers $[ 1, 3, 3 ]$ will be written. After the second operation, the numbers $[ 1, 3 ]$ will be written. Finally, after the third operation, the only number left is $2$.
**Definitions** Let $ n \in \mathbb{Z} $ with $ 2 \leq n \leq 2 \cdot 10^5 $. Let $ S_0 = \{1, 2, 3, \dots, n\} $ be the initial multiset of integers on the board. An operation replaces two numbers $ a, b \in S $ with $ \left\lceil \frac{a + b}{2} \right\rceil $, reducing the size of $ S $ by 1. **Constraints** Perform exactly $ n - 1 $ operations, resulting in a single number $ r \in \mathbb{R} $. **Objective** Minimize the final number $ r $, and output a sequence of $ n - 1 $ pairs $ (a_i, b_i) $ specifying the two numbers chosen in each operation.
API Response (JSON)
{
  "problem": {
    "name": "E. Numbers on Whiteboard",
    "description": {
      "content": "Numbers $1, 2, 3, \\\\dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $frac(a + b, 2)$",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10279E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Numbers $1, 2, 3, \\\\dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $frac(a + b, 2)$...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ with $ 2 \\leq n \\leq 2 \\cdot 10^5 $.  \nLet $ S_0 = \\{1, 2, 3, \\dots, n\\} $ be the initial multiset of integers on the board.  \n\nAn operation replaces two num...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments