Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<real> rs;
    void input() {
        cin >> N;
        rs.resize(N); cin >> rs;
    }

    real d(int i, int j) {
        int a = rs[i], b = rs[j];
        return real(2.0) * sqrt(a * b);
    }

    void solve() {
        vector<real> xs(N, 0);
        for (int i = 0; i < N; i++) {
            real c = rs[i];
            for (int j = 0; j < i; j++) {
                c = max(c, xs[j] + d(j, i));
            }
            xs[i] = c;
        }
        real ans = 0;
        for (int i = 0; i < N; i++) {
            ans = max(ans, xs[i] + rs[i]);
        }
        cout << fixed << setprecision(12) << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}