Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> D(N);
    for (int i = 0; i < N; ++i) cin >> D[i];
    vector<double> pos(N);
    for (int i = 0; i < N; ++i) {
        // i番目の円柱の中心位置を決める
        double now_pos = D[i];
        for (int j = 0; j < i; ++j) {
            double d = 2.0 * sqrt(D[i] * D[j]);
            now_pos = max(now_pos, pos[j] + d);
        }
        pos[i] = now_pos;
    }
    double ans = 0.0;
    for (int i = 0; i < N; ++i) {
        ans = max(ans, pos[i] + D[i]);
    }
    cout << fixed << setprecision(6);
    cout << ans << endl;
    return 0;
}