题目背景
征求翻译。如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献。
题目描述
Farmer John has received a shipment of N large hay bales ($1 \"le N \"le 100,000$), and placed them at various locations along the road leading to his barn. Unfortunately, he completely forgets that Bessie the cow is out grazing along the road, and she may now be trapped within the bales! Each bale $j$ has a size $S_j$ and a position $P_j$ giving its location along the one-dimensional road. Bessie the cow can move around freely along the road, even up to the position at which a bale is located, but she cannot cross through this position. As an exception, if she runs in the same direction for $D$ units of distance, she builds up enough speed to break through and permanently eliminate any hay bale of size strictly less than $D$. Of course, after doing this, she might open up more space to allow her to make a run at other hay bales, eliminating them as well.
Bessie can escape to freedom if she can eventually break through either the leftmost or rightmost hay bale. Please compute the total area of the road consisting of real-valued starting positions from which Bessie cannot escape.
农民约翰已经收到了一批有N个的大型干草包(1<=N<=100,000),并放置在沿着通往他的谷仓的路不同位置。不幸的是,他完全忘记了Bessie牛是放牧的路上,她现在可能被困在那些干草包中!每个干草包J都有一个大小S[J]和一个位置P[J],提供那个干草包在那个一维道路的位置。贝茜奶牛可以在路上自由走动,甚至到这个干草包所在的位置,但她无法穿越这个位置。作为一个例外,如果她在同一个方向跑D个速度单位,她就可以有足够的速度突破,并永久消除任何干草包,只要那个干草包大小严格小于D。当然,在这之后,她会打开更大的空间让她跑向别的干草包,并消除它们。
如果她能突破最左边或最右边的干草包,则贝茜可以逃掉。请计算由实数的起始位置组成的道路最小需要多长,使Bessie不能逃脱。
输入格式:
The first line of input contains $N$. Each of the next $N$ lines describes a
bale, and contains two integers giving its size and position, each in the range
$1\"ldots 10^9$. All positions are distinct.
输入的第一行是N。下面的N行是每个干草堆的大小和位置,每个都在1...10^9的范围内。每个位置都各不相同。
输出格式:
Print a single integer, giving the area of the road from which Bessie cannot
escape.
输出一个整数,也就是使Bessie不能逃脱所需要的路的长度。
输入样例#1:
5
8 1
1 4
8 8
7 15
4 20
输出样例#1:
14