Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin>>n;
  double a[n],d[n],ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i],d[i]=a[i];
    for(int j=0;j<i;j++){
      double x=fabs(a[i]-a[j]),y=a[i]+a[j];
      d[i]=max(d[i],d[j]+sqrt(y*y-x*x));
    }
    ans=max(ans,d[i]+a[i]);
  }
  printf("%.9f\n",ans);
}