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
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef double ld;
#define vc vector
#define st first
#define nd second
#define pll pair<ll, ll>
#define sz(a) (ll)a.size()
#define all(a) a.begin(), a.end()
#define pu push
#define pub push_back
#define pob pop_back
#define em emplace
#define emb emplace_back

void program() {
	ll n, k;
	cin >> n >> k;
	vc<ld> p(n);
	for (ld &pi : p)
		cin >> pi;
	sort(all(p), [&](ld &a, ld &b) {
		return a > b;
	});
	
	const ld EPS = 1e-12;
	vc<pair<ll, ld>> dp;
	dp.pub({0, 1.0});
	ld ans = 0.0;
	for (ll i = 1; i <= n; i++) {
		vc<pair<ll, ld>> tmp = {{dp[0].st - 1, 0.0}};
		for (auto &[j, x] : dp) {
			tmp.back().nd += x * (1 - p[i - 1]);
			tmp.pub({j + 1, x * p[i - 1]});
		}
		ll l = 0;
		while (tmp[l].nd < EPS)
			l++;
		while (tmp.back().nd < EPS)
			tmp.pob();

		dp.clear();
		ld sum = 0.0;
		for (ll j = l; j < sz(tmp); j++) {
			dp.pub(tmp[j]);
			if (tmp[j].st >= k)
				sum += tmp[j].nd;
		}
		ans = max(ans, sum);
	}
	cout << fixed << setprecision(8) << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	program();
	return 0;
}