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
167
168
169
170
171
172
173
174
#include <bits/stdc++.h>


using namespace std;


const int BLOCK = 2000;
const double THRESHOLD = 1e-30;


// Following snippet comes from https://codeforces.com/blog/entry/74209?#comment-583359
// Author: UW / Errichto

#define REP(i, n) for(int i = 0; i < (n); ++i)

template <typename T> void rec_kara(T* a, int one, T* b, int two, T* r) {
    if (min(one, two) <= 20) {
        REP(i, one) REP(j, two) r[i + j] += a[i] * b[j];
        return ;
    }
    const int x = min(one, two);
    if (one < two) rec_kara(a, x, b + x, two - x, r + x);
    if (two < one) rec_kara(a + x, one - x, b, x, r + x);
    const int n = (x + 1) / 2, right = x / 2;
    vector <T> tu(2 * n);
    rec_kara(a, n, b, n, tu.data());
    REP(i, 2 * n - 1) {
        r[i] += tu[i];
        r[i + n] -= tu[i];
        tu[i] = 0;
    }
    rec_kara(a + n, right, b + n, right, tu.data());
    REP(i, 2 * right - 1) r[i + n] -= tu[i], r[i + 2 * n] += tu[i];
    tu[n - 1] = a[n - 1]; tu[2 * n - 1] = b[n - 1];
    REP(i, right) tu[i] = a[i] + a[i + n], tu[i + n] = b[i] + b[i + n];
    rec_kara(tu.data(), n, tu.data() + n, n, r + n);
}

int trim(vector <double> &a) {
    int l = 0, r = (int) a.size() - 1;
    while (l < r && a[l] < THRESHOLD) l++;
    while (l < r && a[r] < THRESHOLD) r--;

    for (int i = 0; i < (int) a.size() - l; i++) {
        a[i] = a[i + l];
    }

    a.resize(r - l + 1);
    return l;
}

template <typename T> vector <T> karatsuba(vector <T> a, vector <T> b) {
    int ta = trim(a), tb = trim(b);

    vector <T> r(a.size() + b.size() - 1);
    rec_kara(a.data(), a.size(), b.data(), b.size(), r.data());

    int t = ta + tb;
    r.resize(r.size() + t, 0.0);

    for (int i = r.size() - 1; i >= t; i--) {
        r[i] = r[i - t];
    }

    for (int i = t - 1; i >= 0; i--) {
        r[i] = 0.0;
    }

    return r;
}

// ----------------------------------------------------------------------

double solve(int n, int t, vector <double> &p) {
    sort(p.begin(), p.end(), greater <double> ());

    int nBlocks = (n + BLOCK - 1) / BLOCK;

    vector <double> blockProd, blockProdPref;

    double ans = 0.0;

    for (int blockId = 0; blockId < nBlocks; blockId++) {
        if (blockId > 0) {
            blockProdPref.resize(blockProd.size());

            blockProdPref.back() = blockProd.back();
            for (int x = (int) blockProdPref.size() - 2; x >= 0; x--) {
                blockProdPref[x] = blockProd[x] + blockProdPref[x + 1];
            }
        }

        vector <double> prod = {1.0};
        for (int i = blockId * BLOCK; i < min((blockId + 1) * BLOCK, n); i++) {
            prod.push_back(0.0);

            int x = (int) prod.size() - 2;
            for (; x >= 3; x -= 4) {
                double np1 = prod[x] * p[i];
                double np2 = prod[x - 1] * p[i];
                double np3 = prod[x - 2] * p[i];
                double np4 = prod[x - 3] * p[i];

                prod[x + 1] += np1;
                prod[x] -= np1;

                prod[x] += np2;
                prod[x - 1] -= np2;

                prod[x - 1] += np3;
                prod[x - 2] -= np3;

                prod[x - 2] += np4;
                prod[x - 3] -= np4;
            }

            for (; x >= 0; x--) {
                double np = prod[x] * p[i];
                prod[x + 1] += np;
                prod[x] -= np;
            }

            int tHere = t + i + 1;
            if (tHere % 2) {
                continue;
            }

            tHere /= 2;

            double ansHere = 0.0;
            for (int x = tHere; x < prod.size(); x++) {
                ansHere += prod[x];
            }

            if (blockId > 0) {
                int xl = max(0, tHere - (int) blockProdPref.size() + 1);
                int xr = min(tHere, (int) prod.size());

                for (int x = xl; x < xr; x++) if (prod[x] > THRESHOLD) {
                    ansHere += prod[x] * blockProdPref[tHere - x];
                }
            }

            ans = max(ans, ansHere);
        }

        if (blockId == nBlocks - 1) {
            break;
        } else if (blockId == 0) {
            blockProd = prod;
        } else {
            blockProd = karatsuba(blockProd, prod);
        }
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

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

    vector <double> p(n);
    for (auto &pi : p) {
        cin >> pi;
    }

    cout << solve(n, t, p);

    return 0;
}