Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

int n;
double r[500];
double ans[500];
double ans2=0;

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