Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

double distan(double a,double b){
	return sqrt(4*a*b);
}

int main(){
	int n;
	cin>>n;
	vector<double> r(n),m(n,0),right(n),left(n);
	for(int i=0;i<n;i++){
	cin>>r[i];
	}
	double ans = 0;
	left[0] = 0;
	right[0] = 2*r[0];
	m[0] = r[0];
	for(int i=1;i<n;i++){
		bool flag = false;
		for(int j = i-1;j>=0;j--){
			double d = distan(r[i],r[j]);
			m[i] = max(d+m[j],m[i]);
		}		
		m[i] = max(m[i],r[i]);
		right[i] =  m[i] + r[i];
	//ans += max(r[i],max(distan(r[i],r[i+1]),r[i+1]));
	}
	sort(right.begin(),right.end());
	printf("%0.10lf\n",right[n-1]);
	
	
	return 0;
}