Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N, X[500];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
  }
  double pos[500] = {}, ret = 0;
  for(int i = 0; i < N; i++) {
    pos[i] = X[i];
    for(int j = 0; j < i; j++) {
      double A = X[j] + X[i], B = X[j] - X[i];
      pos[i] = max(pos[i], pos[j] + sqrt(A * A - B * B));
    }
    ret = max(ret, pos[i] + X[i]);
  }
  cout << fixed << setprecision(10) << ret << endl;
}