Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

double dist(double x, double y, double r) {
    return x + sqrt(pow(y + r, 2.0) - pow(y - r, 2.0));
}

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for (auto &i : v) {cin >> i;}

    vector<double> x(n, 0.0);
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < i; j++) {
            x[i] = max(x[i], dist(x[j], v[j], v[i]));
        }
    }

    double l = 0, r = 0;
    for (int i = 0; i < n; i++) {
        l = min(l, x[i] - v[i]);
        r = max(r, x[i] + v[i]);
    }

    printf("%.8f\n", (r - l));
    
    return 0;
}