Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

double r[1024];
double d[1024];
int n;

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%lf", &r[i]);
    d[i] = r[i];
    for(int j = 0; j < i; ++j) {
      double dz = (r[i] + r[j]);
      double dy = std::abs(r[i] - r[j]);
      double dx = sqrt(dz * dz - dy * dy);
      d[i] = std::max(d[i], d[j] + dx);
    }
  }

  double res = 0.0;
  for(int i = 0; i < n; ++i) {
    res = std::max(res, d[i] + r[i]);
  }
  printf("%.20lf\n", res);
  
  return 0;
}