Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> r(n+1);
    for(int i=0;i<n;i++){
        cin >> r[i+1];
    }
    vector<double> l(n+1);
    l[0]=0;r[0]=0;
    for(int i=1;i<=n;i++){
        l[i]=r[i];
        for(int j=0;j<i;j++){
            l[i]=max(l[i],l[j]+2*sqrt(r[i]*r[j]));
        }
    }
    double ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,l[i]+r[i]);
    }
    cout <<fixed << setprecision(10) << ans << endl;
    return 0;
}