Even Electricity

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

A town gets all its electricity from solar power and a dam that provides hydroelectric power. These sources of energy are not always the most reliable, since the amount of sun and water can vary a lot from day to day. Luckily, the dam has a large reservoir that can store water in order to even out the supply of electricity from day to day.

You will be given information about the nn coming days. On the ii'th day, the solar power station generates s_is\_i units of electricity. At the same time, w_iw\_i units of water will flow into the reservoir. Each unit of water can be converted into one unit of electricity, and you can decide how much you want to convert and how much should be left in the reservoir. However, the reservoir can only hold rr units of water, so at the end of the day the amount of water in the reservoir cannot be larger than rr. In the beginning of the first day the reservoir is empty.

On the first day, there is no water currently stored in the reservoir.  At the end of the last day, the dam will undergo maintenance and must be empty. In other words, all the water that flows into the dam during the nn days must at some point be converted to electricity.

Let e_ie\_i be the amount of electricity produced on the ii'th day. Note that e_i=s_i+r_ie\_i = s\_i + r\_i where r_ir\_i is how much water from the reservoir you converted on the ii'th day. Your task is to find the minimum possible value of  max_i(e_i)min_i(e_i)\max\_i(e\_i) - \min\_i(e\_i).

입력

The first line contains two integers nn and rr (1n1051 \leq n \leq 10^5, 1r1091 \leq r \leq 10^9), the number of days and the amount of water the reservoir can hold.

The following nn lines each contain two integers s_is\_i and w_iw\_i (0s_i,w_i1090 \leq s\_i, w\_i \leq 10^9), the amount of electricity generated by the solar power station, and the amount of water that flowed into the reservoir on the ii'th day.

출력

Output the minimum possible value of max_i(e_i)min_i(e_i)\max\_i(e\_i) - \min\_i(e\_i).