Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;

int n;
double r[510];
double pos[510];

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        pos[i] = r[i];
    }
}

void solve() {
    pos[0] = r[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            pos[i] = max(pos[i], pos[j] + 2 * sqrt(r[i] * r[j]));
        }
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, pos[i] + r[i]);
    }
    cout << setprecision(20) << ans << endl;
}

int main(int argc, char *argv[]) {
    input();
    solve();
    return 0;
}