Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

double f(double r1, double r2) {
	double b = r1 - r2;
	double c = r1 + r2;
	return sqrt(c*c - b*b);
}

signed main() {
	cout << fixed << setprecision(8);
	int N; cin >> N;
	vector<int> r(N); rep(i, 0, N) { cin >> r[i]; }
	vector<double> x(N);

	if (N == 1) {
		cout << r[0] * 2 << endl;
		return 0;
	}

	int jl = 0;
	rep(i, 1, r.size()) {
		rep(j, jl, i) {
			double d = f(r[i], r[j]);
			chmax(x[i], d + x[j]);
		}
		if (r[jl] <= r[i])jl = i;
	}
	double left = INF, right = -INF;
	rep(i, 0, x.size()) {
		chmin(left, x[i] - r[i]);
		chmax(right, x[i] + r[i]);
	}
	dumpc(x);
	cout << right - left << endl;
	return 0;
}