Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N; cin >> N;
    vector<double> r(N),x(N,0);
    for (int i=0;i<N;++i) cin >> r[i];
    for (int i=0;i<N;++i){
        for (int j=0;j<i;++j){
            x[i]=max(x[i],x[j]+sqrt((r[i]+r[j])*(r[i]+r[j])-(r[i]-r[j
            ])*(r[i]-r[j])));
        }
    }
    double Min=0,Max=0;
    for (int i=0;i<N;++i){
        Min=min(Min,x[i]-r[i]);
        Max=max(Max,x[i]+r[i]);
    }
    cout << Max-Min << '\n';
}