Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
int main() {
	int n; cin >> n;
	double out = 0;
	double x[502];
	double dis[502][502];
	rep(i, n) {
		cin >> x[i];
	}
	rep(i, n) {
		dis[0][i+1] = dis[i+1][n + 1] = x[i];
	}
	rep(i, n) {
		Rep(j, i + 1, n) {
			double h = max(x[j] - x[i], x[i] - x[j]);
			double w = x[j]+x[i];
			dis[i + 1][j + 1] = sqrt(w*w - h * h);
		}
	}
	double dp[502] = {}; dp[0] = 0;
	rep1(i, n + 1) {
		per(j, i) {
			dp[i] = max(dp[i], dp[j] + dis[j][i]);
		}
	}
	cout << fixed << setprecision(5) << dp[n + 1] << endl;
	return 0;
}