Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:" ; for(const auto &xxx : v) {std::cerr << xxx << " ";} std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << "\t:" ; for(const auto &xxx : v) {std::cerr << xxx.first << " " << xxx.second << "\n";} std::cerr << "\n";}

typedef complex<double> P;

double getD(P p, double r1, double r2) {
    double sumR = r1 + r2;
    double diffR = r1 - r2;
    return sqrt(sumR * sumR - diffR * diffR);
}

int main() {

    int N;
    cin >> N;

    vector<double> r(N);
    for (int i = 0; i < N; i++) cin >> r[i];

    vector<P> dp(N);

    //x, y
    dp[0] = P(r[0], r[0]);

    for (int i = 1; i < N; i++) {
        double maxV = 1e-10;
        for (int j = 0; j < i; j++) {
            double d = getD(dp[j], r[i], r[j]);
            maxV = max({maxV, d + dp[j].real(), r[i]});
        }
        dp[i] = P(maxV, r[i]);
    }

    double ans = 1e-20;
    for(int i = 0;i<N;i++){
        ans = max(ans, dp[i].real() + dp[i].imag());
    }



//    for (int i = 0; i < N; i++) {
//        cout << fixed << setprecision(10) << dp[i].real() << endl;
//    }
//

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}