Petryk destroys cities
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Uncle Serhiy, who works at the Ministry of Education and Science of Ukraine, took care of the infrastructure for ZNO.
There are \(n\) cities on a coordinate line. The \(i\)-th city is located at the point with coordinate \(x_i\). Also, each city has a parameter \(w_i\) — the message exchange range. A message can be transmitted between cities \(i\) and \(j\) if the distance between them does not exceed \(w_i + w_j\).
Evil Petryk wants to disrupt the ZNO. To do this, he decided to blow up some cities so that between no two remaining cities can messages be transmitted. Since explosives are expensive, Petryk wants to blow up as few cities as possible.
Calculate the minimum number of cities Petryk must blow up to disrupt the ZNO.
Input
The first line contains an integer \(n\) — the number of cities.
Each of the next \(n\) lines contains two integers \(x_i\), \(w_i\) — the coordinate and the message exchange range of each city.
Output
Print a single integer in one line — the minimum number of cities Petryk needs to blow up.
Constraints
\(1 \le n \le 10^5\),
\(0 \le x_i, w_i \le 10^9\),
for 9 tests an additional constraint holds:
\(1 \le n \le 10\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 4 2 11 1 47 7 7 3 47 4 | 2 |
Notes
In the example, Petryk can blow up cities 3 and 4. This is not the only way to achieve the optimal answer.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|