Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class Circle{
public:
	double x,y,r;
	bool leftflag;
	bool rightflag;
};

double square(double x)
{
	return x*x;
}

bool collision(Circle c1,Circle c2)
{
	if(square(c2.x-c1.x)+square(c2.y-c1.y)>=square(c1.r+c2.r)){
		return false;
	}else{
		return true;
	}
}

int main()
{
	int n;

	cin>>n;

	vector<Circle> circle(n);

	rep(i,n){
		cin>>circle[i].r;
		circle[i].x=circle[i].r;
		circle[i].y=circle[i].r;
	}

	rep(i,n){
		rep(j,i){
			if(collision(circle[j],circle[i])==true){
				circle[i].x=circle[j].x+2*sqrt(circle[i].r*circle[j].r);
			}
		}
		
		for(int j=i+1;j<n;j++){
			circle[j].x=max(circle[j].x,circle[i].x);
		}
	}

	double ans=0;

	rep(i,n){
		ans=max(ans,circle[i].x+circle[i].r);
	}

	printf("%.8f\n",ans);

	return 0;
}