Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1e9

int main(){
	int n;
	while(cin>>n){
		vector<double> a(n),cp(n,-INF);
		for(auto &i:a) cin>>i;
		double l=0, r=a[0]*2;
		
		cp[0]=a[0];
		for(int i=1;i<n;i++){
			for(int j=0;j<i;j++){
				double d=a[j]+a[i];
				double h=fabs(a[j]-a[i]);
				cp[i]=max(cp[i],sqrt(d*d-h*h)+cp[j]);
			}
			l=min(l,cp[i]-a[i]);
			r=max(r,cp[i]+a[i]);
		}
		cout<<fixed<<setprecision(13)<<r-l<<endl;
	}
	return 0;
}