Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i, n) cin >> d[i];
  vector<vector<double>> dp(n + 1, vector<double>(10001, -1));
  REP(i, 10001) dp[0][i] = 0;
  REP(i, n) {
    REP(j, 10001) {
      if (dp[i][j] < 0) continue;
      double l = dp[i][j] + sqrt(4 * d[i] * j) - j + d[i];
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      dp[i + 1][d[i]] = max(dp[i + 1][d[i]], l);
    }
  }
  double ans = 0;
  REP(i, 10001) ans = max(ans, dp[n][i]);
  cout << fixed << setprecision(8) << ans << endl;
}