Distribute Bunnies

AtCoder
IDabc434_e
Time2000ms
Memory256MB
Difficulty
There are $N$ rabbits numbered $1$ to $N$ on a number line. Rabbit $i$ is at coordinate $X_i$. Multiple rabbits may be at the same coordinate. Each rabbit has a parameter called **jumping power**, and rabbit $i$ has jumping power $R_i$. Now, all rabbits will jump exactly once. When a rabbit at coordinate $x$ with jumping power $r$ jumps, it moves to coordinate $x+r$ or coordinate $x-r$. If you can freely choose which coordinate each rabbit jumps to, find the maximum possible number of distinct coordinates where rabbits are present after all rabbits have jumped. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $-10^9 \leq X_i \leq 10^9$ * $1 \leq R_i \leq 10^9$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $X_1$ $R_1$ $X_2$ $R_2$ $\vdots$ $X_N$ $R_N$ [samples]
Samples
Input #1
3
4 1
2 3
4 5
Output #1
3

If each rabbit moves as shown below, it is possible to achieve $3$ as the number of distinct coordinates where rabbits are present after jumping, and this is the maximum possible.

*   Rabbit $1$ moves to $4 - 1 = 3$.
*   Rabbit $2$ moves to $2 + 3 = 5$.
*   Rabbit $3$ moves to $4 - 5 = -1$.
Input #2
6
2 1
3 2
6 1
5 2
4 3
4 1
Output #2
4

If each rabbit moves as shown below, it is possible to achieve $4$ as the number of distinct coordinates where rabbits are present after jumping, and this is the maximum possible.

*   Rabbit $1$ moves to $2 - 1 = 1$.
*   Rabbit $2$ moves to $3 + 2 = 5$.
*   Rabbit $3$ moves to $6 + 1 = 7$.
*   Rabbit $4$ moves to $5 + 2 = 7$.
*   Rabbit $5$ moves to $4 - 3 = 1$.
*   Rabbit $6$ moves to $4 - 1 = 3$.
Input #3
10
1000000000 1000000000
1000000000 1
-1000000000 1000000000
-1000000000 1
0 1
2 1
1 2
4 1
3 2
4 3
Output #3
9
API Response (JSON)
{
  "problem": {
    "name": "Distribute Bunnies",
    "description": {
      "content": "There are $N$ rabbits numbered $1$ to $N$ on a number line. Rabbit $i$ is at coordinate $X_i$. Multiple rabbits may be at the same coordinate.   Each rabbit has a parameter called **jumping power**, a",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc434_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ rabbits numbered $1$ to $N$ on a number line. Rabbit $i$ is at coordinate $X_i$. Multiple rabbits may be at the same coordinate.  \nEach rabbit has a parameter called **jumping power**, a...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments