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
158
159
160
161
162
163
164
165
166
#include <bits/stdc++.h>

using namespace std;

#define double long double

typedef complex<double> cd;
const double PI = acos(-1);
const int C = 65536;
vector<double> tree[2 * C + 10];
vector<double> prob;
int n, t;

/*
FFT i ternary search skopiowane z internetow
*/
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]);
    }
    int cnt = 1;
    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];
                cd v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
        cnt++;
    }

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


vector<double> multiplyPoly(const vector<double>& A, const vector<double>& B) {
    vector<cd> fa(A.begin(), A.end()), fb(B.begin(), B.end());
    int n = 1;

    while(n < (int)(A.size() + B.size() - 1)) 
        n <<= 1;

    fa.resize(n); 
    fb.resize(n);
    fft(fa, false);
    fft(fb, false);

    for (int i = 0; i < n; i++) {
        fa[i] *= fb[i];
    }
    fft(fa, true);
    vector<double> res(n);

    for (int i = 0; i < n; i++) {
        res[i] = fa[i].real();
    }

    res.resize(A.size() + B.size() - 1);
    return res;
}

vector<double> getPoly(int x) {
    x += C;
    vector<double> poly = tree[x];
    while(x) {
        if(x % 2 && x > 1)
            poly = multiplyPoly(poly, tree[x - 1]);
        x /= 2;
    }
    return poly;
}

double calc(int pos, int k) {
    int n = pos + 1;
    int L = ceil((k + n) / 2.0);
    vector<double> product = getPoly(pos);
    double res = 0;
    for (int h = L; h < product.size() && h <= n; h++) {
        res += product[h];
    }
    return res;
}

const double EPS = 1e-20;

bool equal(double x, double y) {
    return fabsl(y - x) < EPS;
}

double ternary_search(const vector<int>& vec, const vector<int>& vec2) {
    int left = 0;
    int right = vec.size() - 1;
    double res = 0;
    while (right - left >= 3) {
        int mid1 = left + (right - left) / 3;
        int mid2 = right - (right - left) / 3;
        double res_mid1 = calc(vec[mid1], t);
        double res_mid2 = calc(vec[mid2], t);
        if (res_mid1 < res_mid2 || equal(res_mid1, res_mid2)) {
            res = max(res, res_mid2);
            left = mid1;
        } else {
            res = max(res, res_mid1);
            right = mid2;
        }
    }

    for (int i = left; i <= right; ++i) {
        double res_mid1 = calc(vec[i], t);
        if(res_mid1 > res)
            res = res_mid1;
        if(i < vec2.size()) {
            res_mid1 = calc(vec2[i], t);
            if(res_mid1 > res)
                res = res_mid1;
        }
    }
    return res;
}

void precalc() {
    for (int i = 0; i < n; i++)
        tree[C + i] = {1.0 - prob[i], prob[i]};
    for(int i = n; i <= C; i++)
        tree[C + i] = {1, 0};
    for(int i = C - 1; i > 0; i--)
        tree[i] = multiplyPoly(tree[2 * i], tree[2 * i + 1]);
}

int main(){
    cin>>n>>t;
    for(int i = 1; i <= n; i++) {
        double x;
        cin>>x;
        prob.push_back(-x);
    }
    sort(prob.begin(), prob.end());
    for(int i = 0; i < prob.size(); i++)
        prob[i] = -prob[i];
    precalc();
    vector<int> argsEven, argsOdd;
    for(int i = 0; i < n; i++)
        if(i % 2)
            argsOdd.push_back(i);
        else
            argsEven.push_back(i);

    double res = ternary_search(argsEven, argsOdd);
    printf("%0.9Lf\n", res);
    return 0;
}