Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"



int main() {
	int N; cin >> N;
	vector<ld>rs;
	vector<ld>xs;
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		rs.push_back(a);
	}

	for (int i = 0; i < rs.size(); ++i) {
		ld nx = rs[i];
		for (int j = 0; j < i; ++j) {
			ld dis = sqrt((rs[i] + rs[j])*(rs[i] + rs[j]) - (rs[i] - rs[j])*(rs[i] - rs[j]));
			nx = max(nx, xs[j] + dis);
		}
		xs.push_back(nx);
	}
	ld ans = 0;
	for (int i = 0; i < rs.size(); ++i) {
		ans = max(ans,xs[i] + rs[i]);
	}

	cout << setprecision(22)<<fixed<<ans << endl;
	return 0;
}