Under construction

Still being built. Things may change

Bridge Across Rough Terrain

Time limit1sMemory limit1024 MB

Summary
Find two points on the mountain polyline between A and B, at most L apart, so that the horizontal segment joining them never dips below the terrain.
Level

Medium7 of 10

Topics
Geometry, Two pointers, Sliding window
Solved
No attempts yet

Statement

The profile of the Ural Mountains is a polyline (x1,y1),(x2,y2),…,(xN,yN)(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N) where x1<x2<⋯<xNx_1 < x_2 < \dots < x_N. The starting and ending points of the profile are at sea level, so y1=yN=0y_1 = y_N = 0.

Two distinct points AA and BB lie on the mountain profile, and a road must be built between them. The road runs along the mountain slopes and a horizontal bridge. The length of the bridge must not exceed LL. Both ends of the bridge lie on the profile. The road enters the bridge from one end and leaves from the other. The bridge may not contain any point strictly below the polyline, because no tunnels are built.

Possible bridge placementsAn impossible bridge placement

Input

The first line contains two integers NN and LL, where 2≤N≤100 0002 \le N \le 100\,000 is the number of polyline vertices and 1≤L≤1061 \le L \le 10^6 is the maximum bridge length. The second line contains the coordinates of point AA, and the third line contains the coordinates of point BB. The next NN lines contain the vertices (x1,y1),(x2,y2),…,(xN,yN)(x_1, y_1), (x_2, y_2), \dots, (x_N, y_N) of the polyline.

All coordinates have absolute value at most 10610^6. It is guaranteed that x1<x2<⋯<xNx_1 < x_2 < \dots < x_N, y1=yN=0y_1 = y_N = 0, and that AA and BB lie on the polyline. The points AA and BB are different.

Output

Print the coordinates of the bridge ends on the first and second lines, with at least 5 digits after the decimal point. If several answers exist, print any of them.

Examples2

  1. Example 1

    Input
    4 6
    13 0
    2 1
    1 0
    5 4
    11 -2
    13 0
    
    Expected output
    13.00000 0.00000
    9.00000 0.00000
    
  2. Example 2

    Input
    6 8
    3 -6
    11 -2
    0 0
    4 -8
    6 -4
    7 -4
    9 -6
    12 0
    
    Expected output
    2.00000 -4.00000
    10.00000 -4.00000