Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<double> R(N);
  for(int i = 0; i < N; ++i) cin >> R[i];
  vector<double> X(N);
  double ans = 0;
  for(int i = 0; i < N; ++i){
    double x = R[i];
    for(int j = 0; j < i; ++j)
      x = max(x, X[j]+sqrt((R[i]+R[j])*(R[i]+R[j])-abs(R[i]-R[j])*abs(R[i]-R[j])));
    X[i] = x;
    ans = max(ans, x+R[i]);
  }
  printf("%.12f\n",ans);
}