Problem: Example

Input

2
10 10


Output

40.00000000

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

double calcoo(double r1,double r2){
  //cout << "cal:"<< r1 << " " << r2 <<"->" << sqrt(exp2(r1+r2)-exp2(r1-r2)) <<endl;
  
  if(r1==r2)return 2*r1;
  return sqrt((r1+r2)*(r1+r2)-(r1-r2)*(r1-r2));
}

int main()
{
  int n;

  cin >> n;

  double r[n];
  

  for(int i=0;i<n;i++)
    cin >> r[i];

  vector<double> x;
  vector<double> r_len;
  
  double len=0;
 
  x.push_back(r[0]);
  r_len.push_back(r[0]);
  
  for(int i=1;i<n;i++){
    //???????????§??\????????????????????????
    double max_x=r[i];
    int selected = -1;
    for(int j=0;j<x.size();j++){
      //cout << "x[j]:" << x[j] << endl;
      double tmp = x[j]+calcoo(r[i],r_len[j]); 
      if(max_x< tmp){
	max_x=tmp;
	selected=j;
      }
    }
    //?????°?????????????????????
    //x.erase(v.begin()+selected);
    //r_len.erace(r_len.begin()+selected);
    //cout << max_x << endl;
    x.push_back(max_x);
    r_len.push_back(r[i]);   
  }
  
  double ans=-1.0;
  for(int i=0;i<x.size();i++){
    if(ans<x[i]+r_len[i])ans=x[i]+r_len[i];
  }
  
  printf("%.10f",ans);
  
}