Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cassert>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
double ans,d[500],x[500],cx;
int n;
int main() {
  cin >> n;
  ans = 0;
  rep(i,n){
    cin >> d[i];
    x[i] = d[i];
    rep(j,i){
      cx = x[j]+sqrt((d[i]+d[j])*(d[i]+d[j])-(d[i]-d[j])*(d[i]-d[j]));
      if(x[i]<cx) x[i] = cx;
    }
    if(ans < x[i]+d[i]) ans = x[i]+d[i];
  }
  printf("%.8lf\n",ans);
  return 0;
}