Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
/*
 * 5:51:00
 */

#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

#define MAX_N 500

int n;
double radii[MAX_N],xs[MAX_N];

void compute() {
  xs[0] = radii[0];
  REP(i,1,n) {
    double maxi_x = 0;
    rep(j,i) {
      double tmp_x = -1;
      if( radii[i] == radii[j] ) tmp_x = xs[j] + radii[i] * 2.0;
      else {
	double r1 = radii[i], r2 = radii[j];
	double len_x = sqrt( pow(r1+r2,2.0) - pow(r1-r2,2.0) );
	tmp_x = xs[j] + len_x;
      }
      maxi_x = max(maxi_x,tmp_x);
    }
    xs[i] = maxi_x;
    if( !equals(0.0,xs[i]-radii[i]) && xs[i]-radii[i] < 0 ) {
      xs[i] += fabs(xs[i]-radii[i]);
    }
  }
  double maxi = 0;
  rep(i,n) maxi = max(maxi,xs[i]+radii[i]);
  printf("%.10f\n",maxi);
}

int main() {
  cin >> n;
  rep(i,n) cin >> radii[i];
  compute();
  return 0;
}