Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

int main(){
	int n;
	cin >> n;
	vector< pair<double,double> > p;
	double ans1 = 0;
	double ans2 = 0;
	for(int i = 0 ; i < n ; i++){
		double r;
		cin >> r;
		if( i == 0 ){
			p.push_back({r,0});
		}else{
			double mx = 0;
			for(int j = 0 ; j < i ; j++){
				double dx = sqrt( (r+p[j].first) * (r+p[j].first)  - (r-p[j].first) * (r-p[j].first) );
				mx = max(mx,p[j].second+dx);
			}
			p.push_back({r,mx});
		}
		ans1 = min(ans1,p.back().second - p.back().first);
		ans2 = max(ans2,p.back().second + p.back().first);
	}
	printf("%.10lf\n",ans2-ans1);
}