Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
double ans[4747];
int main(){
  int n;
  cin>>n;
  double r[n],m;
  for(int i=0;i<n;i++){
    cin>>r[i];
    m=r[i];
    for(int j=0;j<i;j++){
      double s=r[i]+r[j],h=r[i]-r[j];
      m=max(m,ans[j]+sqrt(s*s-h*h));
    }
    ans[i]=m;
    //cout<<ans[i]<<endl;
  }
  double a=0;
  for(int i=0;i<n;i++)
    a=max(a,ans[i]+r[i]);
  printf("%.10f\n",a);
}