• محدودیت زمان: ۲ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

There are nn wooden rods vertically placed over a horizontal line. The rods are numbered 11 through nn from left to right. Each rod ii (1in1 \leq i \leq n) is placed at position xix_i and has a height hih_i.

توضیح تصویر

A termite wants to eat all the rods one by one. It starts eating from an arbitrary rod ss (1sn1 \leq s \leq n). Then, after eating a rod ii, the termite selects the next rod to eat based on the following method. Among the remaining rods jj, the one with maximum hjxixjh_j - |x_i - x_j | is selected. If there are ties, the one with minimum xixj|x_i - x_j | is selected. If there are still ties, the left-most rod is selected.

Your task is to calculate the total (horizontal) distance traveled by the termite to eat all the rods.

ورودی

The first line of the input contains two space-separated integers nn, the number of rods, and ss, the starting rod number (1sn100,0001 \leq s \leq n \leq 100, 000). The rods are described in the next nn lines. On the line 1+i1 + i (1in1 \leq i \leq n), the ii-th rod is specified with two space-separated integers xix_i (xi109|x_i | \leq 10^9) and hih_i (1hi1091 \leq h_i \leq 10^9). Additionally, for each ii (1in11 \leq i \leq n - 1), xi<xi+1x_i \lt x_{i+1}.

خروجی

You should print a single integer denoting the total distance traveled by the termite.

مثال

ورودی نمونه ۱

5 3
1 3
4 8
8 2
10 4
11 1
Plain text

خروجی نمونه ۱

17
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.