Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

double getDis(double R,double r){return sqrt((R+r)*(R+r) - (R-r)*(R-r));}

int main(){
  int n;
  cin>>n;
  double A[501],x[501];
  for(int i=0;i<n;i++)cin>>A[i],x[i] = A[i];

  for(int i=1;i<n;i++)
    for(int j=0;j<i;j++){
      double R = A[i];
      double r = A[j];
      double d = getDis(R,r);
      x[i] = max(x[i],x[j]+d);
    }
  
  double ans = 0;
  for(int i=0;i<n;i++) ans=max(ans,x[i]+A[i]);
  printf("%.10f\n",ans);
  return 0;
}