Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n;
    cin >> n;
    vi r(n);
    rep(i,n) cin >> r[i];
    vector<double> x(n);
    rep(i,n){
        x[i] = r[i];
        rep(j,i){
            double h = abs(r[i]-r[j]);
            x[i] = max(x[i], x[j]+sqrt((r[i]+r[j])*(r[i]+r[j]) - h*h));
        }
    }
    double ans = 0;
    rep(i,n)ans = max(ans, x[i] + r[i]);
    cout << shosu(10) << ans << endl;
}