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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

template<typename T>
void updMax(T& a, T b)
{
	a = max(a, b);
}

/**
 * Description: Number-theoretic transform. If you need complex-valued FFT, use the commented out code.
 * Time: O(n \log n)
 */
const db PI = acos(-1.0);
const int LEN = 1 << 17;

typedef complex<db> com;
com pw[LEN];
void init()
{
	db phi = (db)2 * PI / LEN;
	FOR(i, 0, LEN)
		pw[i] = com(cos(phi * i), sin(phi * i));	
}

void fft(vector<com>& a, bool inverse)
{
	int lg = __builtin_ctz(SZ(a));
	FOR(i, 0, SZ(a))
	{
		int k = 0;
		FOR(j, 0, lg)
			k |= ((i >> j) & 1) << (lg - j - 1);
		if(i < k)
			swap(a[i], a[k]);
	}
	for(int len = 2; len <= SZ(a); len *= 2)
	{
		int diff = inverse ? LEN - LEN / len : LEN / len;
		for(int i = 0; i < SZ(a); i += len)
		{
			int pos = 0;
			FOR(j, 0, len / 2)
			{
				com u = a[i + j];
				com v = a[i + j + len / 2] * pw[pos];
				a[i + j] = u + v;
				a[i + j + len / 2] = u - v;
				pos = (pos + diff) % LEN;
			}
		}
	}
	if (inverse)
	{
		FOR(i, 0, SZ(a))
			a[i] /= SZ(a);
	}
}

vector<db> mult(vector<db> a, const vector<db>& b)
{
	int n = SZ(a), m = SZ(b);
	if (n == 0 || m == 0)
		return {};
	int sz = 1, szRes = n + m - 1;
	while(sz < szRes)
		sz *= 2;
	vector<com> ac(ALL(a)), bc(ALL(b));
	ac.resize(sz);
	bc.resize(sz);
	
	fft(ac, false);
	fft(bc, false);
	
	FOR(i, 0, sz)
		ac[i] *= bc[i];
	
	fft(ac, true);
	a.resize(szRes);
	FOR(i, 0, szRes)
		a[i] = ac[i].real();
	return a;
}

struct SegTree
{
	int n;
	vector<vector<db>> t;
	SegTree(int _n)
	{
		n = 1;
		while (n < _n)
			n *= 2;
		t.resize(2 * n - 1);
		n = _n;
	}
	void build(int v, int tl, int tr, const vector<db>& p)
	{
		if (tl + 1 == tr)
		{
			t[v] = {1 - p[tl], p[tl]};
			return;
		}
		int tm = (tl + tr) / 2;
		build(2 * v + 1, tl, tm, p);
		build(2 * v + 2, tm, tr, p);
		t[v] = mult(t[2 * v + 1], t[2 * v + 2]);
	}
	
	void build(const vector<db>& p)
	{
		build(0, 0, n, p);
	}
	
	vector<db> query(int v, int tl, int tr, int r)
	{
		assert(tl <= r - 1);
		if (tr <= r)
		{
			return t[v];
		}
		int tm = (tl + tr) / 2;
		if (tm >= r)
		{
			return query(2 * v + 1, tl, tm, r);
		}
		return mult(query(2 * v + 1, tl, tm, r), query(2 * v + 2, tm, tr, r));
	}
	
	vector<db> query(int r)
	{
		return query(0, 0, n, r);
	}
};

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	init();
	int n, t;
	cin >> n >> t;
	vector<db> p(n);
	for (db& pi : p)
		cin >> pi;
	sort(ALL(p), greater());
	while (!p.empty() && p.back() == 0)
		p.pop_back();
	n = SZ(p);
	if (n < t)
	{
		cout << "0\n";
		return 0;
	}
	SegTree st(n);
	st.build(p);
	auto f = [&](int m)
	{
		const auto& coefs = st.query(m);
		return accumulate(coefs.begin() + (t + m + 1) / 2, coefs.end(), (db)0);
	};
	int l = 0, r = (n - t) / 2;
	while (r - l > 2)
	{
		int m1 = (l + r) / 2, m2 = m1 + 1;
		if (f(t + 2 * m1) < f(t + 2 * m2))
		{
			l = m1;
		}
		else
		{
			r = m2;
		}
	}
	db ans = 0;
	FOR(i, l, r + 1)
	{
		updMax(ans, f(t + 2 * i));
	}
	cout << ans << "\n";
	return 0;
}