Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
int N;
vector<double> R;
int main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    int r; scanf("%d",&r); R.push_back( r );
  }
  vector<double> L;
  for(int i=0;i<N;i++){
    double nl=R[i];
    for(int j=0;j<i;j++){
      double x = R[i] + R[j];
      double y = abs(R[i]-R[j]);
      double z = sqrt( x*x - y*y );
      nl = max( nl, L[j] + z );
    }
    L.push_back( nl );
  }
  double res = 0.0;
  for(int i=0;i<L.size();i++)
    res = max( res, L[i] + R[i] );
  printf("%.9lf\n",res);
}