Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

int main(){
  int n,r[N];
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>r[i];
  double x[N],ans=r[0]*2;
  x[0]=r[0];
  for(int i=1;i<n;i++){
    double maxx=0;
    for(int j=0;j<i;j++){
      int A=r[i]+r[j];
      int B=r[i]-r[j];
      maxx=max(maxx,max(x[j]+sqrt(A*A-B*B),1.0*r[i]));
    }
    x[i]=maxx;
    ans=max(ans,x[i]+r[i]);
  }
  printf("%.8f\n",ans);
  return 0;
}