Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 515;
int r[MAXN];
double pos[MAXN];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> r[i];
    }
    for (int i = 0; i < N; i++) {
        double p = r[i];
        for (int j = 0; j < i; j++) {
            double tmp = sqrt((r[i]+r[j])*(r[i]+r[j]) - (r[i]-r[j])*(r[i]-r[j])) + pos[j];
            p = max(p, tmp);
        }
        pos[i] = p;
    }
    double ans = 0;
    for (int i = 0; i < N; i++) ans = max(ans, pos[i]+r[i]);
    printf("%.15lf\n", ans);
    return 0;
}