Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
// typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e12;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int N;
    cin >> N;
    vector<double> r(N);
    rep(i, N) cin >> r[i];

    vector<double> p;
    p.emplace_back(0);
    rep2(i, 1, N) {
        double l = -INF;
        rep(j, i) {
            double d = 2 * sqrt(r[i] * r[j]);
            double x = p[j] + d;
            l = max(l, x);
        }
        p.emplace_back(l);
    }

    double L = INF, R = -INF;
    rep(i, N) {
        L = min(L, p[i] - r[i]);
        R = max(R, p[i] + r[i]);
    }

    printf("%.10f\n", R - L);

}