Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> b(n);
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	vector<double> x(n);
	x[0]=b[0];
	for(int i=1;i<n;i++){
		x[i]=b[i];
		for(int j=0;j<i;j++){
			x[i]=max(x[i],x[j]+2.0*sqrt(b[i]*b[j]));
		}
	}
	double res=0;
	for(int i=0;i<n;i++){
		res=max(res,x[i]+b[i]);
	}
	printf("%.9f\n",res);
}