Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <cstdio>
#include <cmath>
using namespace std;

#define INF 1e8

int N;
int R[10000];
double x[10000];
int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &R[i]);
		x[i] = 0;
	}
	x[0] = R[0];
	double max = x[0] * 2;
	for(int i = 1; i < N; i++){
		double ans = R[i];
		for(int j = 0; j < i; j++){
			double r = R[i] + R[j];
			double dr = R[i] - R[j];
			ans = fmax(ans, sqrt(r * r - dr * dr) + x[j]);
		}
		x[i] = ans;
		max = fmax(max, x[i] + R[i]);
	}
	printf("%lf\n", max);
}