Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

#define rep(i,n)  for(int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using vi = vector<int>;
using ll = long long;

const double EPS = 1e-8;

using P = complex<double>;
namespace std{
  bool operator <(const P &a, const P &b){
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P &a, const P &b){
  return imag(conj(a)*b);
}
double dot(const P &a, const P &b){
  return real(conj(a)*b);
}
struct L : public vector<P>{
  L(const P &a, const P &b){
    push_back(a);
    push_back(b);
  }
};
struct C{
  P p; double r;
  C(const P &p_, double r_) : p(p_), r(r_) {}
};

P projection(const L &l, const P &p){
  double t = dot(p-l[0],l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

vector<P> crosspointCL(const C &c, const L &l){
  P h = projection(l, c.p);
  double d = abs(h - c.p);
  vector<P> res;
  if(d < c.r - EPS){
    P dir = l[1]-l[0];
    P x = dir / abs(dir) * sqrt(c.r*c.r - d*d);
    res.push_back(h + x);
    res.push_back(h - x);
  }else if(d < c.r + EPS){
    res.push_back(h);
  }
  return res;
}

int main(){
  int n; cin >> n;
  vector<double> rs(n); rep(i,n) cin >> rs[i];
  vector<C> res;
  res.push_back(C(P(rs[0],rs[0]),rs[0]));
  FOR(i,1,n){ // n番目の円の場所を確定させる
    P tmp(rs[i],rs[i]);
    rep(j,i){
      C tmpc(res[j].p,res[j].r+rs[i]);
      // cerr << tmpc.p.real() << " " << tmpc.p.imag() << " " << tmpc.r << endl;
      L tmpl(P(0,rs[i]),P(100,rs[i]));
      vector<P> cross = crosspointCL(tmpc, tmpl);
      sort(cross.begin(), cross.end());
      // cerr << cross.back().real() << " " << cross.back().imag() << endl;
      tmp = max(tmp, cross.back());
    }
    res.push_back(C(tmp,rs[i]));
  }
  double ans = 0;
  rep(i,n){
    ans = max(ans, res[i].p.real()+res[i].r);
    // cerr << i << " " << res[i].p.real() << endl;
  }
  //cout << ans << endl;
  printf("%.10lf\n",ans);
}