Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
#define maxn 510
int r[maxn];
int n;
double dis[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&r[i]);
	double ans=0.0;
	for(int i=0;i<n;i++){
		dis[i]=r[i]*1.0;
		for(int j=0;j<i;j++){
			int x=max(r[i],r[j]),y=min(r[i],r[j]);
			double tmp=sqrt((x+y)*(x+y)*1.0-(x-y)*(x-y)*1.0);
			dis[i]=max(dis[i],dis[j]+tmp);
		}
	}
	for(int i=0;i<n;i++){
		ans=max(ans,dis[i]+r[i]);
	}
	printf("%.8f\n",ans);
}