Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 500 + 5

int n, R[N];
double ans, Pos[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d", R + i);
	for (int i = 1; i <= n; i ++)
	{
		double Max = 1.0 * R[i];
		for (int j = 1; j < i; j ++)
		{
			double x = Pos[j] + 2 * sqrt(1.0 * R[i] * R[j]);
			Max = max(Max, x);
		}
		Pos[i] = Max;
		ans = max(ans, Pos[i] + 1.0 * R[i]);
	}
	printf("%.6lf\n", ans);
	return 0;
}