Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>
#include <cmath>

using namespace std;

int main(){
	
	int n;
	
	cin >> n;
	
	double d[1000] = {};
	double r[1000] = {};
	
	for(int i = 0; i < n; i++){
		cin >> r[i];
		double dist = 0;
		for(int j = 0; j < i; j++){
			dist = max(dist, d[j] + sqrt((r[i] + r[j]) * (r[i] + r[j]) - (r[i] - r[j]) * (r[i] - r[j])) );
		}
		d[i] = dist;
	}
	
	double le = 0;
	double ri = d[n - 1];
	
	for(int i = 0; i < n; i++){
		le = min(le, d[i] - r[i]);
		ri = max(ri, d[i] + r[i]);
	}
	
	printf("%.8f\n", ri - le);
	
	return 0;
}