Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  vector<pair<double,int> > pos;
  double answer=0.0;
  REP(i,n){
    int r;
    cin >> r;
    double tmppos=r;
    REP(j,pos.size()){
      double bpos=pos[j].first;
      int br=pos[j].second;
      tmppos=max(tmppos,bpos+sqrt(1.0*(r+br)*(r+br)-(r-br)*(r-br)));
    }
    pos.push_back(make_pair(tmppos,r));
    answer=max(answer,tmppos+r);
  }
  cout << fixed << setprecision(10) << answer << endl;
  return 0;
}