Problem: Example

Input

4
5
8
58
85


Output

2970.000000000

Solution (in CPP):

Solution:
/*
    厳しい 
 */

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define EPS 10e-6
#define PI 3.14159265358979

int N;
int k;
int r[9];
double ans;

bool check(double x) {
    double sum = 0.0;
    double proposed = 0.0;
    double c = cos(x);

    for (int i=0; i<k; i++) {
        double c2 = (double)(r[0] * r[1]) / (r[i] * r[(i+1)%k]) * c;
        sum += acos(c2);
        proposed += sin(acos(c2)) * r[i] * r[(i+1)%k] / 2;
    }

    if (sum > 2 * PI || sum < 0.0) return false;
    return true;
}

int main() {
    scanf("%d", &N);
    for (int i=0; i<N; i++) {
        scanf("%d", &r[i]);
    }

    sort(r, r+N);
    do {
        for (k=3; k<=N; k++) {
            double low, high;
            double proposed = 0.0;
            double sum = 0.0;

            low = 0.0;
            high = PI;
            for (int i=0; i<100; i++) {
                double mid = (low+high)/2;

                if (check(mid)) low = mid;
                else high = mid;
            }

            for (int i=0; i<k; i++) {
                double c2 = (double)(r[0] * r[1]) / (r[i] * r[(i+1)%k]) * cos(low);
                proposed += sin(acos(c2)) * r[i] * r[(i+1)%k] / 2;
                sum += acos(c2);
            }

            if (abs(sum-2*PI) < EPS) ans = max(ans, proposed);
        }
    } while (next_permutation(r, r+N));

    printf("%f\n", ans);
}