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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double LD;

typedef complex<LD> CD;
const LD PI = acos(-1);

int M = 1<<16;

vector<vector<LD>> tree(2*M+1);

void fft(vector<CD> &a, bool invert) {
    int n = a.size();
    vector<int> rev(n);
    
    for (int i = 0, j = 0; i < n; i++) {
        if (i < j) swap(a[i], a[j]);
        int bit = n >> 1;
        while (j & bit) {
            j ^= bit;
            bit >>= 1;
        }
        j ^= bit;
    }

    for (int len = 2; len <= n; len <<= 1) {
        LD ang = 2 * PI / len * (invert ? -1 : 1);
        CD wn(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];
                CD v = a[i + j + len / 2] * w;
                a[i + j] = u + v;
                a[i + j + len / 2] = u - v;
                w *= wn;
            }
        }
    }

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

vector<LD> multiply(const vector<LD>& a, const vector<LD>& b) {
    int n = 1;
    while (n < (int)(a.size() + b.size())) n <<= 1;

    vector<CD> fa(n), fb(n);
    
    for (size_t i = 0; i < a.size(); i++) fa[i] = a[i];
    for (size_t i = 0; i < b.size(); i++) fb[i] = b[i];

    fft(fa, false);
    fft(fb, false);

    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];

    fft(fa, true);

    vector<LD> result(n);
    for (int i = 0; i < n; i++)
        result[i] = fa[i].real();

    return result;
}



void precompute(vector<LD> & P, int w, int L, int R){
    if(L==R){
        if(L>=P.size()){
            tree[w]={0};
            return;
        }
        tree[w]={1-P[L],0,P[L]};
        return;
    }
    int mid = (L+R)/2;
    precompute(P, 2*w, L, mid);
    precompute(P, 2*w+1, mid+1, R);
    tree[w] = multiply(tree[2*w], tree[2*w+1]);
}

vector<LD> query(vector<LD> & P, int w, int L, int R, int x){
    if(L > x || R < x)return {0};
    if(L==R)return tree[w];
    int mid = (L+R)/2;
    if(x<=mid){
        return query(P, 2*w, L, mid, x);
    }else{
        return multiply(tree[2*w], query(P, 2*w+1, mid+1, R, x));
    }
}

LD check(vector<LD> & P, int n, int t){
    n = min(n, (int)P.size());
    vector<LD> tab = query(P, 1, 0, M-1, n-1);
    LD wyn=0;
    for(int i=n+t;i<=2*n;i++)wyn+=tab[i];
    return wyn;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);

    int n, t;
    cin>>n>>t;

    vector<LD> P(n);

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

    sort(P.begin(),P.end(),[](LD a, LD b){return a > b;});

    precompute(P, 1, 0, M-1);

    LD wynik = 0;

    int L = 0;
    int R = n/2+1;
    while(L<R){
        // cout<<L<<" "<<R<<endl;
        int mid1 = (L+L+R)/3;
        int mid2 = (L+R+R)/3;
        if(check(P, mid1*2+1, t) > check(P, mid2*2+1, t))R = mid2 - 1;
        else L = mid1 + 1;
    }
    wynik = max(wynik, check(P, L*2-1, t));
    wynik = max(wynik, check(P, L*2+1, t));
    wynik = max(wynik, check(P, L*2+3, t));
    L = 0;
    R = n/2+1;
    while(L<R){
        // cout<<L<<" "<<R<<endl;
        int mid1 = (L+L+R)/3;
        int mid2 = (L+R+R)/3;
        // cout<<L<<" "<<R<<endl;
        // cout<<mid1<<" "<<mid2<<" | "<<check(P, mid1*2, t) << " " << check(P, mid2*2, t)<<endl;
        if(check(P, mid1*2, t) > check(P, mid2*2, t))R = mid2 - 1;
        else L = mid1 + 1;
    }
    wynik = max(wynik, check(P, L*2-2, t));
    wynik = max(wynik, check(P, L*2, t));
    wynik = max(wynik, check(P, L*2-2, t));
    cout.precision(10);
    cout<<fixed<<wynik<<endl;
    

    return 0;
}