Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;

int n;
double t[567];
double x[567];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    if(n == 1)
    {
        printf("%.6f\n", 2 * t[0]);
    }
    else
    {
        x[0] = t[0];
        for(int i = 1; i < n; i++)
        {
            int id = -1;
            double rightm = -1.0;
            for(int j = 0; j < i; j++)
            {
                double nu = x[j] + sqrt(fabs(t[i] + t[j]) * fabs(t[i] + t[j]) - fabs(t[i] - t[j]) * fabs(t[i] - t[j]));
                if(nu > rightm)
                {
                    rightm = nu;
                    id = i;
                }
            }
            x[i] = rightm;
        }
        double lm = 999999999.0, rm = -999999999.0;
        for(int i=0;i<n;i++) lm = min(lm, x[i] - t[i]);
        for(int i=0;i<n;i++) rm = max(rm, x[i] + t[i]);
        printf("%.6f\n", rm - lm);
    }

return 0;
}