Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

int N;
double D[501];
double xs[501];
int main(){

  cin>>N;
  for(int i=0;i<N;i++){
    cin>>D[i];
  }

  xs[0] = D[0];
  
  // ????????????????????????????????????
  for(int i = 1; i < N; i++){
    double max_x = -1;
    for(int j = 0; j < i; j++){
      double nxt_x = 0;
      nxt_x = xs[j] + sqrt(pow(1.0*D[i] + D[j], 2) - pow(abs(D[i] - D[j]), 2));
      max_x = max(max_x, nxt_x);
    }
    xs[i] = max_x;
  }

  double max_x = -1;
  double min_x = 100000000;
  for(int i=0;i<N;i++){
    max_x=max(max_x, xs[i] + D[i]);
    min_x=min(min_x, xs[i] - D[i]);
  }
  double ans = abs(min_x-max_x);
  printf("%.10f\n", ans);
  
  return 0;
}