Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
static const int MAX_N = 500;

int N;
double r[MAX_N];

double memo[MAX_N];

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lf", &r[i]);
	for(int i = 0; i < N; i++){
		memo[i] = r[i];
		for(int j = 0; j < i; j++){
			memo[i] = max(memo[i], memo[j] + sqrt(pow(r[i] + r[j], 2.0) - pow(fabs(r[i] - r[j]), 2.0)));
		}
	}
	double res = 0.0;
	for(int i = 0; i < N; i++) res = max(res, memo[i] + r[i]);
	printf("%.8lf\n", res);
	return 0;
}