Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<double> r(n);
	for(int i=0; i<n; i++){
		cin >> r[i];
	}
	vector<double> c(n, 0);
	c[0] = r[0];
	double right = r[0]*2;
	for(int i=1; i<n; i++){
		for(int j=0; j<i; j++){
			c[i] = max(c[i], c[j] +sqrt((r[i]+r[j])*(r[i]+r[j]) -abs((r[j]-r[i])*(r[j]-r[i]))));
		}
		if(c[i] < r[i]) c[i] = r[i];
		right = max(right, c[i]+r[i]);
	}
	cout << fixed << setprecision(10);
	cout << right << endl;
    return 0;
}