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

using ld = long double;

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N, T;
	cin >> N >> T;
	vector<ld> prob(N);
	for(int i = 0; i < N; i++) cin >> prob[i];
	sort(prob.rbegin(), prob.rend());
	vector<ld> dp = {1};
	int st = 0;
	ld best = 0;

	ld EPS = 1e-14;
	ld phigh = 0;
	for(ld p : prob){
		vector<ld> ndp(dp.size() + 1, 0);
		st -= 1;
		for(int i = 0; i < (int)dp.size(); i++){
			ndp[i] += (1 - p) * dp[i];
			ndp[i+1] += p * dp[i];
		}
		{
			int c = 0;
			while(ndp[c] < EPS) c++;
			ndp.erase(ndp.begin(), ndp.begin() + c);
			st += 2 * c;
		}
		{
			while(ndp.back() < EPS){
				if(st + 2 * ((int)ndp.size() - 1) >= T) phigh += ndp.back();
				ndp.pop_back();
			}
		}
		dp = ndp;
		ld pwin = 0;
		bool any = false;
		for(int i = 0; i < (int)dp.size(); i++){
			if(st + 2 * i >= T){
				pwin += dp[i];
				any = true;
			}
		}
		if(any) pwin += phigh;
		best = max(best, pwin);
	}
	cout << fixed << setprecision(9);
	cout << best << '\n';
}