Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

using namespace std;

int main(){
	int N;
	while(cin >> N){
		vector<double> vd, r(N);
		for(double& d : r) cin >> d;
		double res = 0.0;
		for(int i=0;i<N;i++){
			double d = r[i];
			for(int j=0;j<i;j++){
				double sum = r[i] + r[j];
				double dif = abs(r[i] - r[j]);
				d = max(d, vd[j] + sqrt(sum*sum - dif*dif));
			}
			vd.push_back(d);
			res = max(res, d + r[i]);
		}
		printf("%.10lf\n", res);
	}
}