Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<ld> r(n);
    for (int i = 0; i < n; i++)
        cin >> r[i];
    vector<ld> dp(n, INF);
    ld res = 0;
    for (int i = 0; i < n; i++)
    {
        dp[i] = r[i];
        for (int j = 0; j <= i - 1; j++)
        {
            ld d = sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j]));
            dp[i] = max(dp[i], dp[j] + d);
        }
        // cout<<i<<" "<<dp[i]<<endl;
        res = max(res, dp[i] + r[i]);
    }
    cout << fixed << setprecision(10) << res << endl;
}