Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int n;

double len(int r1,int r2)
{
    return sqrt((r1+r2)*(r1+r2) - (r1-r2)*(r1-r2));
}

int main()
{
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    vector<double> v(n);
    double ans = 0;
    rep(i,n){
        double mn = vec[i];
        for(int j=0;j<i;j++){
            mn = max(mn,len(vec[i],vec[j])+v[j]);
        }
        v[i] = mn;
        ans = max(ans,mn+vec[i]);
    }
    printf("%.10f\n",ans);
}