/// UH Top #include <bits/stdc++.h> #define db(x) cerr << #x << ':' << (x) << '\n'; #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() // #define int ll using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; // typedef __int128_t int128; typedef pair<ll, ll> pii; typedef pair<ld, ll> pdi; typedef pair<ld, ld> pdd; typedef pair<ld, pdd> pdp; typedef pair<string, ll> psi; typedef pair<ll, string> pls; typedef pair<string, string> pss; typedef pair<ll, pii> pip; typedef pair<pii, pii> ppp; // typedef complex<ld> point; // typedef vector<point> polygon; typedef vector<ll> vi; // typedef pair<point, int> ppi; #define prec(n) \ cout.precision(n); \ cout << fixed const ll mod = (1e9 + 7); const ld eps = (1e-9); const ll oo = (ll)(1e9 + 5); #define pi acos(-1) #define MAXN (ll)(4e2 + 5) struct point { double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} }; point operator+(const point &a, const point &b) { return {a.x + b.x, a.y + b.y}; } point operator-(const point &a, const point &b) { return {a.x - b.x, a.y - b.y}; } point operator*(const point &a, const point &b) { return {a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x}; } point operator/(const point &a, double d) { return {a.x / d, a.y / d}; } void fft(vector<point> &a, int sign = 1) { int n = a.size(); // n should be a power of two double theta = 8 * sign * atan(1.0) / n; for (int i = 0, j = 1; j < n - 1; ++j) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (j < i) swap(a[i], a[j]); } for (int m, mh = 1; (m = mh << 1) <= n; mh = m) { int irev = 0; for (int i = 0; i < n; i += m) { point w = point(cos(theta * irev), sin(theta * irev)); for (int k = n >> 2; k > (irev ^= k); k >>= 1) ; for (int j = i; j < mh + i; ++j) { int k = j + mh; point x = a[j] - a[k]; a[j] = a[j] + a[k]; a[k] = w * x; } } } if (sign == -1) for (auto &p : a) p = p / n; } vector<point> convolve(vector<point> &a, vector<point> &b) { int n = a.size(); int m = b.size(); int sum = n + m; while (sum != (sum & -sum)) sum += (sum & -sum); while (a.size() < sum) a.push_back(point(0, 0)); while (b.size() < sum) b.push_back(point(0, 0)); fft(a, 1); fft(b, 1); vector<point> res(sum); for (int i = 0; i < sum; i++) res[i] = a[i] * b[i]; fft(res, -1); return res; } vector<point> convolve_vectors(vector<vector<point>> &v) { if (v.size() == 1) return v[0]; vector<vector<point>> m[2]; for (int i = 0; i < v.size(); i++) { m[i & 1].push_back(v[i]); } auto a = convolve_vectors(m[0]); auto b = convolve_vectors(m[1]); return convolve(a, b); } double aux(vector<double> &p, int x, int t) { vector<vector<point>> to_conv(x); for (int i = 0; i < x; i++) { to_conv[i] = {point(1 - p[i], 0), point(p[i], 0)}; } auto conv = convolve_vectors(to_conv); double ans = 0; for (int i = 0; i <= x; i++) { if (i - (x - i) >= t) { ans += conv[i].x; } } return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, t; cin >> n >> t; vector<double> p(n); for (auto &x : p) cin >> x; sort(allr(p)); int ans = t; for (int i = (1 << 15); i; i >>= 1) { if (ans + i > n) continue; int x1 = ans + i - 1; int x2 = ans + i; double v1 = aux(p, x1, t); double v2 = aux(p, x2, t); // cout << x1 << ' ' << v1 << '\n'; // cout << x2 << ' ' << v2 << '\n'; if (v2 > v1 + eps) { ans += i; } } prec(15); // cout << ans << '\n'; cout << aux(p, ans, t) << '\n'; return 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 | /// UH Top #include <bits/stdc++.h> #define db(x) cerr << #x << ':' << (x) << '\n'; #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() // #define int ll using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; // typedef __int128_t int128; typedef pair<ll, ll> pii; typedef pair<ld, ll> pdi; typedef pair<ld, ld> pdd; typedef pair<ld, pdd> pdp; typedef pair<string, ll> psi; typedef pair<ll, string> pls; typedef pair<string, string> pss; typedef pair<ll, pii> pip; typedef pair<pii, pii> ppp; // typedef complex<ld> point; // typedef vector<point> polygon; typedef vector<ll> vi; // typedef pair<point, int> ppi; #define prec(n) \ cout.precision(n); \ cout << fixed const ll mod = (1e9 + 7); const ld eps = (1e-9); const ll oo = (ll)(1e9 + 5); #define pi acos(-1) #define MAXN (ll)(4e2 + 5) struct point { double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} }; point operator+(const point &a, const point &b) { return {a.x + b.x, a.y + b.y}; } point operator-(const point &a, const point &b) { return {a.x - b.x, a.y - b.y}; } point operator*(const point &a, const point &b) { return {a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x}; } point operator/(const point &a, double d) { return {a.x / d, a.y / d}; } void fft(vector<point> &a, int sign = 1) { int n = a.size(); // n should be a power of two double theta = 8 * sign * atan(1.0) / n; for (int i = 0, j = 1; j < n - 1; ++j) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (j < i) swap(a[i], a[j]); } for (int m, mh = 1; (m = mh << 1) <= n; mh = m) { int irev = 0; for (int i = 0; i < n; i += m) { point w = point(cos(theta * irev), sin(theta * irev)); for (int k = n >> 2; k > (irev ^= k); k >>= 1) ; for (int j = i; j < mh + i; ++j) { int k = j + mh; point x = a[j] - a[k]; a[j] = a[j] + a[k]; a[k] = w * x; } } } if (sign == -1) for (auto &p : a) p = p / n; } vector<point> convolve(vector<point> &a, vector<point> &b) { int n = a.size(); int m = b.size(); int sum = n + m; while (sum != (sum & -sum)) sum += (sum & -sum); while (a.size() < sum) a.push_back(point(0, 0)); while (b.size() < sum) b.push_back(point(0, 0)); fft(a, 1); fft(b, 1); vector<point> res(sum); for (int i = 0; i < sum; i++) res[i] = a[i] * b[i]; fft(res, -1); return res; } vector<point> convolve_vectors(vector<vector<point>> &v) { if (v.size() == 1) return v[0]; vector<vector<point>> m[2]; for (int i = 0; i < v.size(); i++) { m[i & 1].push_back(v[i]); } auto a = convolve_vectors(m[0]); auto b = convolve_vectors(m[1]); return convolve(a, b); } double aux(vector<double> &p, int x, int t) { vector<vector<point>> to_conv(x); for (int i = 0; i < x; i++) { to_conv[i] = {point(1 - p[i], 0), point(p[i], 0)}; } auto conv = convolve_vectors(to_conv); double ans = 0; for (int i = 0; i <= x; i++) { if (i - (x - i) >= t) { ans += conv[i].x; } } return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, t; cin >> n >> t; vector<double> p(n); for (auto &x : p) cin >> x; sort(allr(p)); int ans = t; for (int i = (1 << 15); i; i >>= 1) { if (ans + i > n) continue; int x1 = ans + i - 1; int x2 = ans + i; double v1 = aux(p, x1, t); double v2 = aux(p, x2, t); // cout << x1 << ' ' << v1 << '\n'; // cout << x2 << ' ' << v2 << '\n'; if (v2 > v1 + eps) { ans += i; } } prec(15); // cout << ans << '\n'; cout << aux(p, ans, t) << '\n'; return 0; } |