Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int N;
  scanf("%d", &N);
  vi R(N);
  vector<double> O(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> R[i];
  }
  double width = R[0] * 2;
  O[0] = R[0];
  for (int i = 1; i < N; i++) {
    if (width <= R[i] * 2) {
      width = R[i] * 2;
      O[i] = R[i];
    }
    for (int j = 0; j < i; j++) {
      double w = sqrt( 1.0 - pow((double)(R[j] - R[i]) / (R[j] + R[i]), 2.0) ) * (R[j] + R[i]) + O[j] + R[i];
      width = max(width, w);
      O[i] = max(O[i], w - R[i]);
    }
  }
  printf("%.9f\n", width);
}