Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<iostream>
#include<cmath>
#include<iomanip>
#define dis(a,b)sqrt(((a)+(b))*((a)+(b))-((a)-(b))*((a)-(b)))
using namespace std;
int n;double d[500],p[500];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>d[i];
	for(int i=0;i<n;i++)
	{
		p[i]=d[i];
		for(int j=0;j<i;j++)
		{
			double now=dis(d[j],d[i])+p[j];
			p[i]=max(p[i],now);
		}
	}
	double ans=0;
	for(int i=0;i<n;i++)
	{
		ans=max(ans,p[i]+d[i]);
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}