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> p(n);
	p[0]=0.0;
	double left=-r[0], right=r[0];
	for(int i=1; i<n; i++){
		double newpos=0.0;
		for(int j=0; j<i; j++){
			newpos = max(newpos, p[j] +sqrt((r[i]+r[j])*(r[i]+r[j]) -(r[i]-r[j])*(r[i]-r[j])));
		}
		p[i] = newpos;
		left = min(left, newpos-r[i]);
		right = max(right, newpos+r[i]);
	}
	
	cout << fixed;
	cout << setprecision(6);
	cout << right -left << endl;
	return 0;
}