Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<ld> r(N), x(N, 0);
	for (int i = 0; i < N;i++) cin >> r[i];
	for (int i = 0;i < N;i++) {
		if (i == 0) { x[i] = r[i]; }
		else {
			ld l = -1;
			for (int j = 0; j < i; j++) {
				l = max(l, x[j] + sqrt((r[i] + r[j])*(r[i] + r[j]) - (r[i] - r[j])*(r[i] - r[j])));
			}
			x[i] = l;
		}
	}
	ld left = 0, right = 0;
	for (int i = 0; i < N;i++) {
		left = min(x[i] - r[i], left);
		right = max(x[i] + r[i], right);
	}
	cout << fixed << setprecision(10) << right - left << endl;
}