Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  double r[512], l[512];
  for(int i = 0; i < N; i++) cin >> r[i];
  double ans = 0.0;
  for(int i = 0; i < N; i++){
    l[i] = r[i];
    for(int j = 0; j < i; j++){
      l[i] = max(l[i], l[j] + sqrt((r[i]+r[j])*(r[i]+r[j]) - (r[i]-r[j])*(r[i]-r[j])));
    }
    ans = max(ans, l[i] + r[i]);
  }
  printf("%.10f\n", ans);
  return 0;
}