cswork / OA打开练习工作台

TradeDeskOA #2

Light Sources

估计中等可在线判题

考点(AI 标注)前缀和区间

There are n lamps on a number line. Lamp i is at integer coordinate x_i and has a positive integer radius r_i; it lights the whole range from x_i−r_i to x_i+r_i (both ends included).

Find the number of integer coordinates lit by exactly 1 lamp.

输入格式

The first line contains an integer n. Each of the next n lines contains two integers x_i and r_i. 1≤n≤100000, −10^9≤x_i≤10^9, 1≤r_i≤10^9.

输出格式

Output one integer: the number of integer coordinates lit by exactly one lamp.

样例 1

输入:

3
-2 3
2 3
2 1

输出:

6

样例 2

输入:

2
0 1
4 1

输出:

6

样例 3

输入:

2
0 3
1 1

输出:

4

样例说明

Example 1: the three lamps light [−5,1], [−1,5], and [1,3]. The numbers of lamps lighting the points of −6..6 are, in order, 0,1,1,1,1,2,2,3,2,2,1,1,0, and the coordinates lit exactly once are −5,−4,−3,−2,4,5, 6 in total. Example 2: [−1,1] and [3,5] do not intersect, giving 6 coordinates in total. Example 3: [−3,3] contains [0,2], so only −3,−2,−1,3 are lit by exactly one lamp, and the answer is 4.