Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<double> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  vector<double> pos(n);
  pos[0] = a[0];
  for(int i=1;i<n;++i) {
    pos[i] = pos[i-1];
    for(int j=0;j<i;++j) {
      double tmp = sqrt(pow(a[j]+a[i],2)-pow(abs(a[i]-a[j]),2)+eps);
      pos[i] = max(pos[i], pos[j] + tmp);
    }
  }
  double l = 0, r = pos[n-1] + a[n-1];
  for(int i=0;i<n;++i) {
    l = min(l, pos[i] - a[i]);
    r = max(r, pos[i] + a[i]);
  }
  // printv(a);
  // printv(pos);
  // cout << l << ":" << r << endl;
  cout << r-l << endl;

}