Balloon Connect-the-Dots
Time limit2sMemory limit512 MB
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.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Math, Implementation
- Solved
- No attempts yet
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 dots, each labelled with an integer between and . You draw straight lines: one between and , one between and , one between and , and so on to the end. Here is an example before and after connecting the dots.

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 dots on the surface and labelled them from to . As the balloon inflates, the dots move further and further apart. My goal is the largest possible picture, so the total length of the 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 lines. I can increase the volume of the balloon by cubic centimetres per minute, and I can draw at a speed of centimetres per minute. When I draw the line from point to point , 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 minutes in total. The time spent inflating the balloon plus the time spent drawing must be at most minutes. When I stop, all lines must be fully drawn. Find the largest total line length I can draw.
Input
The first line contains four integers , , and , where () is the number of points, () is the time available to both inflate the balloon and draw the lines in minutes, () is the rate at which I can inflate the balloon in cubic centimetres per minute, and () is the speed at which I can draw in centimetres per minute.
The next lines describe the points in order from to , with the balloon centred at the origin. Each line holds two real numbers and and an integer (), giving the point on the surface at where . It is guaranteed that , and and are in centimetres. Each and 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 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 . Rounding can leave stored as a tiny negative value such as , and taking its square root then fails. For the same reason the cosine of the angle between two points can land slightly outside . Clamping that value to the range before taking the arc cosine is the safe fix.