Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
double r[555];
double dist[555];

int main(){
  cin>>n;
  rep(i,n)cin>>r[i];
  rep(i,n){
    double maxd=2*r[i];
    rep(j,i){
      double dist2=dist[j]-r[j];
      maxch(maxd,dist2+sqrt(pow(r[i]+r[j],2)-pow(r[i]-r[j],2))+r[i]);
    }
    dist[i]=maxd;
  }
  printf("%.10f\n", *max_element(dist,dist+n));
	return 0;
}