Find the fewest leading drops so every W by H rectangle inside the L by L pot contains a drop strictly inside, or report -1.
Hard8Binary searchSegment treeGeometryNo attempts yetTime limit2sMemory limit256 MBElly keeps an L by L pot full of flowers on her terrace. She and Stancho often sit beside it and talk while watching the flowers. Once it starts raining, Elly stops listening to Stancho and watches where the drops land. She goes back to listening the moment she decides the flowers are well watered, and Stancho wants to know when that moment comes.
The upper surface of the pot is a square in the coordinate plane, and its corners are (0,0), (0,L), (L,L) and (L,0). During the rain, N drops fall into the pot one after another.
Elly considers the flowers well watered once every W×H rectangle that fits inside the pot has at least one drop strictly inside it. The sides of the rectangle are parallel to the sides of the pot. The side of length W is parallel to the x axis and the side of length H is parallel to the y axis. The rectangle may not stick out of the pot, so its lower left corner (x,y) is any real point with 0≤x≤L−W and 0≤y≤L−H.
A drop (Xi,Yi) is strictly inside such a rectangle when x<Xi<x+W and y<Yi<y+H. A drop that lands on the border of the rectangle does not count as being inside it.
Find how many drops have fallen at the moment the flowers first become well watered.
The first line contains the number of drops N, the side length of the pot L, and the width W and height H of the rectangle Elly looks at.
Each of the next N lines contains the coordinates Xi and Yi of one drop, in the order the drops fall.
Print, on a single line, the number of drops that have fallen at the moment the flowers first become well watered. If some W×H rectangle still has no drop strictly inside it after all N drops have fallen, print -1 instead.
In the first example, after the 13th drop lands at (4,2), no 5×4 rectangle without a drop strictly inside it is left.