Afraid of the Dark

easyPrefix Sum

Genie has taken the responsibility of protecting his neighbourhood; by becoming the watchman.

Every night he walks the main street, starting from the watchtower at $$$0$$$ and ending at his house at index $$$p$$$. There is only one road through which travel is possible ($$$i.e$$$, the $$$x-axis$$$).

There are $$$n$$$ street lamps on the $$$x-axis$$$. The $$$i_\text{th}$$$ street lamp is situated at $$$x_i$$$ and has a range $$$r_i$$$ so that it can light up the range $$$[x_i - r_i, x_i + r_i]$$$. Note that the light rays are self destructive in nature ($$$i.e$$$, any co-ordinate lit up by more than one lamp will remain dark)

Genie is afraid of the dark, and wishes to know before hand the maximum number of continuous integer co-ordinates he has to travel in the dark while heading to his house.

Input Format:

The first line of each test case contains two integers $$$n$$$, $$$p$$$ $$$(1 \le p \le 2.10^5$$$ and $$$ 0 \le n \le 2.10^5)$$$ — The number of street lights and index of Genie's house respectively.

The next $$$n$$$ lines contain two space seperated integers $$$x_i$$$ and $$$r_i$$$ — The position of the $$$i_\text{th}$$$ street light and its range.

Output Format:

Output a single integer, the maximum number of continous integer co-ordinates Genie has to travel in the dark while going towards his house.

Examples:

Example 1:

Input:

1 7
2 0

Output:

5

Example 2:

Input:

4 4
1 2
3 0
0 2
3 0

Output:

5

Note:

In the last test case:

The points lit by first street lamp are $$$[0, 1, 2, 3]$$$

The points lit by second street lamp are $$$[3]$$$

The points lit by third street lamp are $$$[0, 1, 2]$$$

The points lit by fourth street lamp are $$$[3]$$$

Therefore $$$[0, 1, 2, 3]$$$ will recieve lamp from more than one street lamp and hence will remain dark, the point $$$[4]$$$ doesn't receive lamp from any of the street lights, so it will also remain dark.

Hence the maximum continuous integer points that will remain dark are $$$[0, 1, 2, 3, 4]$$$. The answer is $$$5$$$.

Code

Loading Editor...