Time limit
1s
Memory limit
128 MB
There is a grid made of N horizontal lines and N vertical lines. The distance between two adjacent horizontal lines or two adjacent vertical lines is 1. An intersection is written as (x, y) when it lies on the x-th vertical line from the left and the y-th horizontal line from the bottom. The bottom-left intersection is S = (1, 1).
A single wire is placed on the grid under these rules:
S, and the endpoints are joined together.The input gives the bend points of the wire in the order they are visited. The wire starts at S, visits those bend points in order, and then returns to S.
The grid is then cut by a vertical line parallel to the grid's vertical lines. This cutting line passes exactly halfway between the I-th vertical line and the (I + 1)-th vertical line. It is guaranteed that the cut divides the wire into at least two pieces.
Given the wire and the cutting line, find the length of the longest piece of wire after the cut.
The first line contains N, the number of horizontal lines and also the number of vertical lines (2 <= N <= 1,000,000).
The second line contains K, the number of bend points of the wire (1 <= K <= 100,000).
Each of the next K lines contains two integers x and y, the coordinates of a bend point.
The last line contains I, meaning that the cutting line passes between the I-th vertical line and the (I + 1)-th vertical line (1 <= I <= N - 1).
Print the length of the longest piece among the pieces created by the cut.