Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <cstdio> //{{{
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define ALL(c) (c).begin(), (c).end()
#define DUMP(x) std::cerr << #x << ':' << (x) << '\n';

typedef long long ll;

inline int in(){int x;scanf("%d",&x);return x;}
template<typename T, typename U>inline bool chmax(T&x,U a){if(x>=a)return 0;x=a;return 1;}
template<typename T, typename U>inline bool chmin(T&x,U a){if(x<=a)return 0;x=a;return 1;}
//}}}

using namespace std;

#include <cmath>

double X[550];
int R[550];

inline double sq(double x){ return x * x; }

int main()
{
  int N = in();
  for (int i = 0; i < N; i++) R[i] = in();
  for (int i = 0; i < N; i++) {
    X[i] = R[i];
    for (int j = 0; j < i; j++){
      if (R[i] == R[j]) {
        chmax(X[i], X[j] + R[i] + R[j]);
      }
      else {
        chmax(X[i], X[j] + sqrt(sq(R[i] + R[j]) - sq(R[i] - R[j])));
      }
    }
  }
  double maxi = 0;
  for (int i = 0; i < N; i++) chmax(maxi, X[i] + R[i]);
  printf("%.10lf\n", maxi);

  return 0;
}