Balloon Connect-the-Dots

Choose an inflation time so the remaining time lets you draw all n-1 surface segments at speed d, maximizing total drawn length on the inflated sphere.

Medium7GeometryBinary searchMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Have you ever played connect-the-dots? For those of us with no talent for drawing, it is one of the few ways to end up with a nice picture. The page has nn dots, each labelled with an integer between 11 and nn. You draw n1n-1 straight lines: one between 11 and 22, one between 22 and 33, one between 33 and 44, and so on to the end. Here is an example before and after connecting the dots.

A connect-the-dots example

Today you are drawing a connect-the-dots picture on the surface of a balloon. Assume the balloon is a perfect sphere. It starts with a radius of 1 centimetre. I have drawn nn dots on the surface and labelled them from 11 to nn. As the balloon inflates, the dots move further and further apart. My goal is the largest possible picture, so the total length of the n1n-1 line segments should be as large as possible.

Because I do not want the image to look faded, I will first inflate the balloon and only then draw the n1n-1 lines. I can increase the volume of the balloon by vv cubic centimetres per minute, and I can draw at a speed of dd centimetres per minute. When I draw the line from point ii to point i+1i+1, I draw it along the surface of the balloon on a shortest path. Sometimes several shortest paths exist, but this problem only counts lengths, so it does not matter which one I draw.

I have TT minutes in total. The time spent inflating the balloon plus the time spent drawing must be at most TT minutes. When I stop, all n1n-1 lines must be fully drawn. Find the largest total line length I can draw.

Input

The first line contains four integers nn, TT, vv and dd, where nn (2n10002 \le n \le 1000) is the number of points, TT (1T1061 \le T \le 10^6) is the time available to both inflate the balloon and draw the n1n-1 lines in minutes, vv (1v10001 \le v \le 1000) is the rate at which I can inflate the balloon in cubic centimetres per minute, and dd (1d10001 \le d \le 1000) is the speed at which I can draw in centimetres per minute.

The next nn lines describe the points in order from 11 to nn, with the balloon centred at the origin. Each line holds two real numbers xx and yy and an integer ss (s{1,1}s \in \{-1, 1\}), giving the point on the surface at (x,y,z)(x, y, z) where z=s1x2y2z = s\sqrt{1 - x^2 - y^2}. It is guaranteed that 0x2+y210 \le x^2 + y^2 \le 1, and xx and yy are in centimetres. Each xx and yy is given to at most 6 digits after the decimal point.

Lines may cross one another or overlap completely, so a segment of the surface may be counted more than once. It is guaranteed that I can draw the picture on the balloon of radius one in at most TT minutes.

Output

Print the length in centimetres of the largest completed drawing I can make. Round to 6 digits after the decimal point and print exactly 6 of them.

Hint

Be careful when x2+y2=1x^2 + y^2 = 1. Rounding can leave 1x2y21 - x^2 - y^2 stored as a tiny negative value such as 0.0000000001-0.0000000001, and taking its square root then fails. For the same reason the cosine of the angle between two points can land slightly outside [1,1][-1, 1]. Clamping that value to the range before taking the arc cosine is the safe fix.