Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
	int N;
	double d[505], x[505]={0.0}, ans=0.0;
	
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> d[i];
		x[i] = d[i];
		for(int j=0; j<i; j++){
			double h = abs( d[i]-d[j] );
			double r = d[i] + d[j];
			double w = sqrt( r*r - h*h );
			x[i] = max(x[i], x[j]+w);
		}
		ans = max(ans, x[i] + d[i]);
	}
	printf("%0.6f\n", ans);

	return 0;
}