1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <bits/stdc++.h>
#include <iomanip>
#include <random>
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) X.begin(), X.end()
#define sz(X) int(size(X))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
using pii = pair<int, int>; using vi = vector<int>;
using ll = long long; using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) { *(int *)0 = 0; });
#define DTP(x, y) auto operator << (auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; }
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) { (( cerr << x << ", " ), ...) <<
'\n'; }
#define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#define deb(...) 0
#endif
 

//kod FFT i conv z kactla
// oryginał: https://github.com/kth-competitive-programming/kactl/blob/main/content/numerical/FastFourierTransform.h
// wersja z odpowiednimi makrami: https://github.com/KacperTopolski/kactl/blob/main/content/numerical/FastFourierTransform.h
typedef complex<double> C;
typedef vector<double> vd;
void fft(vector<C>& a) {
	int n = sz(a), L = 31 - __builtin_clz(n);
	static vector<complex<long double>> R(2, 1);
	static vector<C> rt(2, 1);
	for (static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0L, acos(-1.0L) / k);
		fwd(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
	}
	vi rev(n);
	rep(i,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	rep(i,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
	for (int k = 1; k < n; k *= 2)
		for (int i = 0; i < n; i += 2 * k) rep(j,k) {
			auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k]; 
			C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]);
			a[i + j + k] = a[i + j] - z;
			a[i + j] += z;
		}
}
vd conv(const vd& a, const vd& b) {
	if (a.empty() || b.empty()) return {};
	vd res(sz(a) + sz(b) - 1);
	int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
	vector<C> in(n), out(n);
	copy(all(a), begin(in));
	rep(i,sz(b)) in[i].imag(b[i]);
	fft(in);
	for (C& x : in) x *= x;
	rep(i,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	rep(i,sz(res)) res[i] = imag(out[i]) / (4 * n);
	return res;
}
//koniec kodu z kactla

vd p;

vd rangePoly(int a, int b){
    if(a == b){
        return {1 - p[a], p[a]};
    }
    int m = (a + b) / 2;
    vd l = rangePoly(a, m);
    vd r = rangePoly(m+1, b);
    return conv(l, r);
}

const int K = 1000;

const int TEST = 1e9;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n, t; cin >> n >> t;
    p.resize(n);
    rep(i, n)cin >> p[i];
    // int n = 50000;
    // int t = 12500;
    // mt19937_64 rng(2137);
    // p.resize(n);
    // rep(i, n){
    //     double x = (rng() % (TEST + 1));
    //     p[i] = x / TEST;
    // }
    sort(all(p), greater<double>());
    vd pol = rangePoly(0, t-1);
    double res = 0;
    res = max(res, pol[t]);
    vector<double> v(2*K + 1);
    vector<double> newV(2*K + 1);
    for(int a = t; a < n; a += 2*K){
        int b = min(a + 2*K - 1, n-1);
        for(int i = 0; i <= 2*K; i++){
            int ind = t + ((a-t) / 2) + i - K;
            if(0 <= ind && ind < sz(pol)){
                v[i] = pol[ind];
            }else{
                v[i] = 0.0;
            }
        }
        double tail = 0;
        for(int ind = t + ((a-t) / 2) + K + 1; ind < sz(pol); ind++){
            tail += pol[ind];
        }
        for(int i = a; i + 1 <= b; i += 2){
            rep(j, 2*K+1)newV[j] = 0;
            double x = (1.0 - p[i]) * (1.0 - p[i+1]);
            double z = p[i] * p[i+1];
            double y = max(1.0 - x - z, 0.0);
            rep(j, 2*K - 1){
                newV[j] += x * v[j];
                newV[j+1] += y * v[j];
                newV[j+2] += z * v[j];
            }
            newV[2*K - 1] += x * v[2*K - 1];
            newV[2*K] += y * v[2*K - 1];
            tail += z * v[2*K - 1];
            newV[2*K] += x * v[2*K];
            tail += y * v[2*K];
            tail += z * v[2*K];
            v = newV;
            double here = 0.0;
            for(int j = K + 1 + (i-a)/2; j <= 2*K; j++){
                here += v[j];
            }
            res = max(res, here + tail);
        }
        pol = conv(pol, rangePoly(a, b));
    }
    cout << res << "\n";
    return 0;
}