Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int n;
	cin >> n;
	
	vector<int> r(n);
	rep(i, n) cin >> r[i];
	
	vector<double> dp(n);
	
	rep(i, n){
		dp[i] = 1.0 * r[i];
		for(int j = i - 1; j >= 0; j--){
			int tmp1 = r[i] + r[j];
			int tmp2 = r[i] - r[j];
			dp[i] = max(dp[i], dp[j] + sqrt(tmp1 * tmp1 - tmp2 * tmp2));
		}
	}
	double ans = 0;
	
	rep(i, n) ans = max(ans, dp[i] + (double)r[i]);
	
	printf("%.8lf\n", ans);
	return 0;
}