#P9455. [入门赛 #14] 塔台超频 (Hard Version)

[入门赛 #14] 塔台超频 (Hard Version)

Problem Description

There are nn towers on a straight road. They are numbered 1,2,,n1, 2, \cdots, n in order, and are located at distances a1,a2,,ana _ 1, a _ 2, \cdots, a _ n from the start of the road (a1<a2<<ana _ 1 < a _ 2 < \cdots < a _ n).

Each tower initially has a communication radius b1,b2,,bnb _ 1, b _ 2, \cdots, b _ n. This means that tower ii can communicate with towers whose positions are within the range [aibi,ai+bi][a _ i - b _ i, a _ i + b _ i].

Note in particular: for two towers A and B, B can transmit a signal to A if and only if A's position is within B's communication range. Note that this is not the same as “their communication ranges overlap, so they can communicate”.

Now you can overclock these towers. Specifically, you may choose a voltage kk, and then all towers will have their voltage increased by kk, so their communication radii will each increase by kk. Here kk can only be a non-negative integer.

You are required to overclock the towers so that a signal can be transmitted from tower 11 to tower nn, with no restriction on the path (that is, you only need the signal to reach tower nn from tower 11 in some way). However, unreasonable overclocking will seriously wear out the towers, so you want to make the overclocking voltage as small as possible.

Compute the minimum voltage needed for overclocking to achieve the goal above.

Input Format

The input has n+1n + 1 lines.

The first line contains an integer nn, representing the number of towers.
The next nn lines each contain two integers ai,bia _ i, b _ i, representing the position and the initial communication radius of each tower.

Output Format

Output one line with one integer, representing the minimum voltage needed for overclocking to achieve the goal.

10
2 3
5 0
6 3
7 2
8 0
10 0
13 2
14 4
15 4
18 2
3

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 2n5×1052 \leq n \leq 5 \times 10 ^ 5, and 0ai,bi1090 \leq a _ i, b _ i \leq 10 ^ 9.

Translated by ChatGPT 5