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
148
149
150
151
152
153
154
155
156
157
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define PB push_back
#define EB emplace_back
#define FI first
#define SE second
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pii>
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define ALL(X) (X).begin(),(X).end()
#ifndef DEBUG
#define endl (char)10
#endif
using namespace std;
using ll = long long;
using ld = double;

template <class T>
ostream& operator<< (ostream& os, vector<T>& vec){
    for(auto& t : vec) os << t << " ";
    return os;
}
template<class T, class U>
ostream& operator<< (ostream& os, const pair<T, U>& p){
    os << p.FI << " " << p.SE;
    return os;
}
template<class T, class U>
istream& operator>> (istream& is, pair<T, U>& p){
    is >> p.FI >> p.SE;
    return is;
}
template <class T>
istream& operator>> (istream& is, vector<T>& vec){
    for(auto& p : vec) is >> p;
    return is;
}

// https://cp-algorithms.com/algebra/fft.html

using cd = complex<ld>;
const ld PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();

    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;

        if (i < j)
            swap(a[i], a[j]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}

const int BLOCK = (1 << 11);

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<ld> V(n);
    cin >> V;
    sort(ALL(V), greater<ld>());

    int npo2 = BLOCK;
    while(npo2 <= n) npo2 *= 2;
    n = npo2;
    while(V.size() < npo2) V.PB(0.0);

    vector<ld> dp(n, 0.0);
    vector<ld> dpsp(n + 1, 1.0);
    dp[0] = 1.0;
    ld ans = dpsp[0] = 0.0;
    t--;

    vector<cd> dp_fft(n);
    vector<cd> dpb_fft(n);

    int BLX = n / BLOCK;

    vector<ld> dpb(BLOCK + 1, 0.0);
    vector<ld> dpb2(BLOCK + 1, 0.0);

    int from = 0;
    int to = BLOCK;

    FOR(bbb,0,BLX){

		dpb.assign(BLOCK + 1, 0.0);
		dpb2.assign(BLOCK + 1, 0.0);
		dpb[0] = 1.0;
		FOR(i,0,BLOCK) {
            int truei = i + from;
		    dpb2[0] = dpb[0] * V[truei];
            FOR(j,1,i+2) dpb2[j] = dpb[j] * V[truei] + (1.0 - V[truei]) * dpb[j - 1];
            swap(dpb, dpb2);
            if(truei >= t && (truei - t) % 2 == 0) {
                ld cans = 0.0;
                int k = (truei - t) / 2;
                int lim = min(k + 1, BLOCK + 1);
                FOR(j,0,lim) cans += dpsp[k - j + 1] * dpb[j];
                /*if(truei > 24920 && truei < 24930) {
                    cout << k << " + " << truei << " -> " << cans << endl;
                    cout << dpb << endl;
                    cout << dpsp << endl;
                    FOR(j,0,lim) cout << dpsp[k - j + 1] << " " << dpb[j] << endl;
                }*/
                ans = max(ans, cans);
            }
		}
		FOR(i,0,n) dp_fft[i] = dp[i];
		FOR(i,0,n) dpb_fft[i] = (i < dpb.size() ? dpb[i] : 0.0);
		fft(dp_fft, false);
		fft(dpb_fft, false);
		FOR(i,0,n) dp_fft[i] *= dpb_fft[i];
		fft(dp_fft, true);
		FOR(i,0,n) {
            dp[i] = abs(dp_fft[i]);
            dpsp[i + 1] = dpsp[i] + dp[i];
		}

		from += BLOCK;
		to   += BLOCK;
	}
	//cerr << "ZMIENIC PRECYZJE!!!!" << endl;
	cout << fixed << setprecision(15) << ans << endl;
}