Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#define FOR(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
#define MAXN (2000)
double r[MAXN],p[MAXN];
int main (int argc, char *argv[])
{
	int n;
	while (scanf("%d",&n)!=EOF){

		double ans=0;
		FOR(i,1,n){
			scanf("%lf",&r[i]);

			p[i]=r[i];
			FOR(j,1,i-1){
				int dr=r[j]+r[i];
				int tr=r[j]-r[i];
				double nowp=sqrt(dr*dr-tr*tr)+p[j];
				p[i]=max(p[i],nowp);
			}

			ans=max(ans,p[i]+r[i]);
		}
		printf("%.8f\n",ans);


	}
	return 0;
}