Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P, double> C;



int main(){
  int n;
  cin >> n;
  double r[n], p[n];
  for(int i = 0; i < n; ++i){
    cin >> r[i];
    p[i] = r[i];
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < i; ++j){
      p[i] = max(p[i],
		 p[j]+sqrt((r[i]+r[j])*(r[i]+r[j])-(r[i]-r[j])*(r[i]-r[j])));
    }
  }
  double ans = 0;
  for(int i = 0; i < n; ++i)
    ans = max(ans, p[i]+r[i]);
  printf("%.10lf\n", ans);
  return 0;
}