Problem F
Matchstick Men

A group of $n^2-n$ identical matchstick men are building a matchstick structure where $2n-2$ matchsticks are lined up on a horizontal line with $n$ marked points, with one matchstick propped up at either end and $2$ matchsticks each at the interior points. The tops of each pair of matchsticks touch (and melt into a single point). These matchsticks then form $n-1$ triangles, and another group of matchstick men will build on top of these triangles’ top vertices until a single pair of matchsticks touches to form the top of this structure. Given the placements of the men at the bottom, how high will their structure be?
Input
The first line of input contains an integer $n$ ($2 \le n \le 50$), followed by a real number $t$ ($1 \le t \le 10$), which is the length of each matchstick. The second line of input contains $n-1$ real numbers $a_ i$ where $a_ i$ is the distance between the $i^{\text {th}}$ and $(i+1)^{\text {th}}$ matchstick man. It is guaranteed that $2t > a_ i$ for all values $a_ i$. All real numbers will have no more than $3$ digits after the decimal point.
Output
Output the height of the matchstick structure. Your answer will be considered correct if it is within an absolute error of $10^{-6}$ of the real answer.
Sample Input 1 | Sample Output 1 |
---|---|
2 2 2 |
1.73205080756887720 |
Sample Input 2 | Sample Output 2 |
---|---|
6 5 5 4 7 3 5 |
21.58323995415637600 |
Sample Input 3 | Sample Output 3 |
---|---|
6 5 5 4 7 2.985 5 |
21.58559211845467000 |