Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
double r[601];
double dist[601];
int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&r[i]);
	}
	dist[0]=r[0];
	for(int i=1;i<n;i++){
		dist[i]=r[i];
		for(int j=0;j<i;j++){
			dist[i]=max(dist[i],dist[j]+sqrt(4.0*r[i]*r[j]));
		}
	}
	double res=0;
	for(int i=0;i<n;i++){
		res=max(res,dist[i]+r[i]);
	}
	printf("%.10f\n",res);
	return 0;
}