Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long

using namespace std;

signed main() {
    int N;
    cin >> N;

    double r[500];
    double pos[500];
    for (int i = 0; i < N; i++) {
	cin >> r[i];
    }

    int arg = 0;
    pos[0] = r[0];
    for (int i = 1; i < N; i++) {
	double maxPos = -1;
	for (int j = 0; j < i; j++) {
	    double tmpPos = sqrt((r[j]+r[i])*(r[j]+r[i]) - (r[j]-r[i])*(r[j]-r[i]));
	    maxPos = max(pos[j] + tmpPos, maxPos);
	}
	maxPos = max(maxPos, r[i]);
	pos[i] = maxPos;
    }

    double maxPos = 0;
    for (int i = 0; i < N; i++) {
	maxPos = max(maxPos, pos[i]+r[i]);
    }
    printf("%.10f\n", maxPos);
    
    return 0;
}