Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
#define sqr(x) (x) * (x)

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n; cin >> n;
    vector<int> r(n);
    for (int &ri: r) cin >> ri;
    vector<double> x(n);
    for (int i = 0; i < n; i++) x[i] = r[i];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            double d = x[j] + sqrt(sqr(r[i] + r[j]) - sqr(r[i] - r[j]));
            chmax(x[i], d);
        }
    }
    double ans = 0;
    for (int i = 0; i < n; i++) chmax(ans, x[i] + r[i]);
    cout << ans << endl;
    return 0;
}