Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

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

using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;

  vector<int> a(n);
  vector<double> dp(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[i] = (double)a[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      dp[i] = max(dp[i], 2.0 * sqrt(a[j] * a[i]) + dp[j]);
    }
  }

  double ans = 0.0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i] + a[i]);
  }
  printf("%.10f\n", ans);

  return 0;
}