Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 505
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,r[M];
double X[M],ans;
int main()
{
	while(~scanf("%d",&n))
	{
		REP(i,1,n) RI(r[i]);
		X[1] = r[1];
		
		REP(i,2,n)
		{
			X[i] = r[i];
			
			REP(j,1,i-1)
			{
				double lim = r[j] + r[i];
				lim *= lim;
				lim -= pow(abs(r[j]-r[i]), 2);
				lim = sqrt(lim);

				X[i] = max(X[i], X[j]+lim);
			}
		}

		ans=0.0;
		REP(i,1,n)
		{
			ans = max(ans, X[i]+r[i]);
		}
		printf("%.10f\n",ans);
	}
	return 0;
}