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;
double solve(double r1,double r2){
  return sqrt((r2+r1)*(r2+r1)-(r2-r1)*(r2-r1));
}
int main(void)
{
  int n;
  cin >> n;
  vector<double> r(n);
  REP(i,n) cin >> r[i];
  vector<double> o(n,0.0);
  double answer=0.0;
  REP(i,n){
    o[i]=max(o[i],r[i]);
    REP(j,i){
      o[i]=max(o[i],o[j]+solve(r[j],r[i]));
    }
    answer=max(answer,o[i]+r[i]);
  }
  cout << fixed << setprecision(10) << answer << endl;
}