Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 555;
int N;
double R[MAXN];
double pos[MAXN];

int main() {
  while (cin >> N) {
    for (int i = 0; i < N; ++i) {
      cin >> R[i];
    }
    for (int i = 0; i < N; ++i) {
      double x = R[i];
      for (int j = 0; j < i; ++j) {
	double c = R[i] + R[j];
	double b = R[i] - R[j];
	double a = sqrt(c * c - b * b);
	x = max(x, pos[j] + a);
      }
      pos[i] = x;
    }
    double res = 0;
    for (int i = 0; i < N; ++i) {
      res = max(res, pos[i] + R[i]);
    }
    printf("%.10f\n", res);
  }
  return 0;
}