#include <bits/stdc++.h>
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) X.begin(), X.end()
#define sz(X) int(size(X))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
using pii = pair<int, int>; using vi = vector<int>;
using ll = long long; using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) { *(int *)0 = 0; });
#define DTP(x, y) auto operator<<(auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; }
auto operator<<(auto &o, auto a) -> decltype(all(a), o);
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
#define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", [](auto... arg_) { (( cerr << arg_ << ", " ), ...) << '\n'; }(x)
#else
#define deb(...) 0
#endif
typedef complex<double> C;
typedef vector<double> vd;
void fft(vector<C>& a) {
int n = sz(a), L = 31 - __builtin_clz(n);
static vector<complex<long double>> R(2, 1);
static vector<C> rt(2, 1); // (^ 10% faster if double)
for (static int k = 2; k < n; k *= 2) {
R.resize(n); rt.resize(n);
auto x = polar(1.0L, acos(-1.0L) / k);
fwd(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
}
vi rev(n);
rep(i,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
rep(i,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
for (int k = 1; k < n; k *= 2)
for (int i = 0; i < n; i += 2 * k) rep(j,k) {
// C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled) /// include-line
auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k]; /// exclude-line
C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]); /// exclude-line
a[i + j + k] = a[i + j] - z;
a[i + j] += z;
}
}
vd conv(const vd& a, const vd& b) {
if (a.empty() || b.empty()) return {};
vd res(sz(a) + sz(b) - 1);
if (min(sz(a), sz(b)) <= 20) {
rep(i, sz(a)) rep(j, sz(b))
res[i + j] += a[i] * b[j];
return res;
}
int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
vector<C> in(n), out(n);
copy(all(a), begin(in));
rep(i,sz(b)) in[i].imag(b[i]);
fft(in);
for (C& x : in) x *= x;
rep(i,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
fft(out);
rep(i,sz(res)) res[i] = imag(out[i]) / (4 * n);
return res;
}
double atLeast(vector<double> questions, int t) {
assert(sz(questions));
auto rec = [&](auto _rec, int l, int r) -> vector<double> {
if (l == r) {
return {1 - questions[l], questions[l]};
}
int mid = (l + r) / 2;
return conv(
_rec(_rec, l, mid),
_rec(_rec, mid+1, r)
);
};
int qs = sz(questions);
questions = rec(rec, 0, qs - 1);
double ans = 0;
rep(i, sz(questions)) {
if (i - (qs - i) >= t)
ans += questions[i];
}
return ans;
}
double brute(vector<double> questions, int t) {
sort(questions.rbegin(), questions.rend());
double best = 0;
vector<double> dp = {1};
for (auto q : questions) {
dp.pb(0);
double here = 0;
for (int i = sz(dp) - 1; i >= 0; --i) {
dp[i] = (1-q) * dp[i] + q * (i ? dp[i-1] : 0);
int nok = sz(dp)-1 - i;
if (i - nok >= t) here += dp[i];
}
best = max(best, here);
}
return best;
}
void solve() {
int n, t;
#ifdef CHECK
n = 50000; t = 12800;
#else
cin >> n >> t;
#endif
vector<double> questions(n);
#ifdef CHECK
mt19937_64 rnd(chrono::high_resolution_clock().now().time_since_epoch().count());
for (auto &q : questions) q = uniform_real_distribution()(rnd);
#else
for (auto &q : questions) cin >> q;
#endif
sort(questions.rbegin(), questions.rend());
double best = 0;
vector<double> big = {1}, prefbig = {1}, small = {1};
for (auto q : questions) {
if (sz(small) % 750 == 0) {
big = conv(big, small);
prefbig.resize(sz(big));
prefbig.back() = big.back();
for (int i = sz(big) - 2; i >= 0; --i)
prefbig[i] = prefbig[i+1] + big[i];
small = {1};
}
small.pb(0);
for (int i = sz(small) - 1; i; --i)
small[i] = small[i-1] * q + small[i] * (1 - q);
small[0] *= 1 - q;
int qSoFar = sz(small) + sz(big) - 2;
if ((t + qSoFar) % 2)
continue;
if (qSoFar < t)
continue;
int hasToAnswer = (t + qSoFar) / 2;
double here = 0;
rep(ansSmall, sz(small)) {
int ansBig = hasToAnswer - ansSmall;
if (ansBig < 0) ansBig = 0;
if (ansBig >= sz(big)) continue;
here += small[ansSmall] * prefbig[ansBig];
}
best = max(best, here);
}
#ifdef LOC
if (n < 1000) {
double br = brute(questions, t);
if (abs(br - best) > 1e-7) {
deb(n, t);
deb(questions);
deb(br, best);
assert(false);
}
}
#endif
cout << best << '\n';
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int z = 1;
// cin >> z;
rep(_, z) solve();
cout << flush;
_Exit(0);
}
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 | #include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) fwd(i, 0, n) #define all(X) X.begin(), X.end() #define sz(X) int(size(X)) #define pb push_back #define eb emplace_back #define st first #define nd second using pii = pair<int, int>; using vi = vector<int>; using ll = long long; using ld = long double; #ifdef LOC auto SS = signal(6, [](int) { *(int *)0 = 0; }); #define DTP(x, y) auto operator<<(auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; } auto operator<<(auto &o, auto a) -> decltype(all(a), o); DTP(o << a.st << ", " << a.nd, a.nd); DTP(for (auto i : a) o << i << ", ", all(a)); #define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", [](auto... arg_) { (( cerr << arg_ << ", " ), ...) << '\n'; }(x) #else #define deb(...) 0 #endif typedef complex<double> C; typedef vector<double> vd; void fft(vector<C>& a) { int n = sz(a), L = 31 - __builtin_clz(n); static vector<complex<long double>> R(2, 1); static vector<C> rt(2, 1); // (^ 10% faster if double) for (static int k = 2; k < n; k *= 2) { R.resize(n); rt.resize(n); auto x = polar(1.0L, acos(-1.0L) / k); fwd(i,k,2*k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2]; } vi rev(n); rep(i,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2; rep(i,n) if (i < rev[i]) swap(a[i], a[rev[i]]); for (int k = 1; k < n; k *= 2) for (int i = 0; i < n; i += 2 * k) rep(j,k) { // C z = rt[j+k] * a[i+j+k]; // (25% faster if hand-rolled) /// include-line auto x = (double *)&rt[j+k], y = (double *)&a[i+j+k]; /// exclude-line C z(x[0]*y[0] - x[1]*y[1], x[0]*y[1] + x[1]*y[0]); /// exclude-line a[i + j + k] = a[i + j] - z; a[i + j] += z; } } vd conv(const vd& a, const vd& b) { if (a.empty() || b.empty()) return {}; vd res(sz(a) + sz(b) - 1); if (min(sz(a), sz(b)) <= 20) { rep(i, sz(a)) rep(j, sz(b)) res[i + j] += a[i] * b[j]; return res; } int L = 32 - __builtin_clz(sz(res)), n = 1 << L; vector<C> in(n), out(n); copy(all(a), begin(in)); rep(i,sz(b)) in[i].imag(b[i]); fft(in); for (C& x : in) x *= x; rep(i,n) out[i] = in[-i & (n - 1)] - conj(in[i]); fft(out); rep(i,sz(res)) res[i] = imag(out[i]) / (4 * n); return res; } double atLeast(vector<double> questions, int t) { assert(sz(questions)); auto rec = [&](auto _rec, int l, int r) -> vector<double> { if (l == r) { return {1 - questions[l], questions[l]}; } int mid = (l + r) / 2; return conv( _rec(_rec, l, mid), _rec(_rec, mid+1, r) ); }; int qs = sz(questions); questions = rec(rec, 0, qs - 1); double ans = 0; rep(i, sz(questions)) { if (i - (qs - i) >= t) ans += questions[i]; } return ans; } double brute(vector<double> questions, int t) { sort(questions.rbegin(), questions.rend()); double best = 0; vector<double> dp = {1}; for (auto q : questions) { dp.pb(0); double here = 0; for (int i = sz(dp) - 1; i >= 0; --i) { dp[i] = (1-q) * dp[i] + q * (i ? dp[i-1] : 0); int nok = sz(dp)-1 - i; if (i - nok >= t) here += dp[i]; } best = max(best, here); } return best; } void solve() { int n, t; #ifdef CHECK n = 50000; t = 12800; #else cin >> n >> t; #endif vector<double> questions(n); #ifdef CHECK mt19937_64 rnd(chrono::high_resolution_clock().now().time_since_epoch().count()); for (auto &q : questions) q = uniform_real_distribution()(rnd); #else for (auto &q : questions) cin >> q; #endif sort(questions.rbegin(), questions.rend()); double best = 0; vector<double> big = {1}, prefbig = {1}, small = {1}; for (auto q : questions) { if (sz(small) % 750 == 0) { big = conv(big, small); prefbig.resize(sz(big)); prefbig.back() = big.back(); for (int i = sz(big) - 2; i >= 0; --i) prefbig[i] = prefbig[i+1] + big[i]; small = {1}; } small.pb(0); for (int i = sz(small) - 1; i; --i) small[i] = small[i-1] * q + small[i] * (1 - q); small[0] *= 1 - q; int qSoFar = sz(small) + sz(big) - 2; if ((t + qSoFar) % 2) continue; if (qSoFar < t) continue; int hasToAnswer = (t + qSoFar) / 2; double here = 0; rep(ansSmall, sz(small)) { int ansBig = hasToAnswer - ansSmall; if (ansBig < 0) ansBig = 0; if (ansBig >= sz(big)) continue; here += small[ansSmall] * prefbig[ansBig]; } best = max(best, here); } #ifdef LOC if (n < 1000) { double br = brute(questions, t); if (abs(br - best) > 1e-7) { deb(n, t); deb(questions); deb(br, best); assert(false); } } #endif cout << best << '\n'; } int32_t main() { cin.tie(0)->sync_with_stdio(0); cout << fixed << setprecision(10); int z = 1; // cin >> z; rep(_, z) solve(); cout << flush; _Exit(0); } |
English