Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<double> vec(n);
  vector<double> pos(n);
  rep(i,n) cin>>vec[i];

  pos[0] = vec[0];
  repl(i,1,n){
    double best = vec[i];
    rep(j,i){
      double c = vec[i]+vec[j];
      double b = abs(vec[i]-vec[j]);
      best = max(best, pos[j] + sqrt(c*c - b*b));
    }
    pos[i] = best;
  }

  double ans = 0;
  rep(i,n) ans = max(ans, pos[i]+vec[i]);

  printf("%.9f\n", ans);

  return 0;
}