Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<double> a(n), x(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    x[0] = a[0];
    double ans = a[0] * 2.0;    
    rep(i, 1, n){
        x[i] = a[i];
        rep(j, 0, i){
            x[i] = max(x[i], x[j] + 2.0 * sqrt(a[i] * a[j]));
        }
        ans = max(ans, x[i] + a[i]);
    }
    printf("%.12f\n", ans);
}