Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

int n, p[510];
double d[510];

void solve(int tc){
	scanf("%d", &n);
	for(int i=1;i<=n;i++)scanf("%d", p+i);
	for(int i=1;i<=n;i++){
		d[i] = p[i];
		for(int j=i-1;j;j--){
			d[i] = max(d[i], d[j] + 2*sqrt(p[i] * p[j]));
		}
	}
	double ans = 0;
	for(int i=1;i<=n;i++)ans = max(ans, d[i] + p[i]);
	printf("%.8f\n", ans);
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}