#include #include #include #include using namespace std; #pragma warning(disable: 4996) /*string ID = "01"; FILE *in = freopen(("./in" + ID + ".txt").c_str(), "r", stdin); FILE *out = freopen(("./out" + ID + ".txt").c_str(), "w", stdout);*/ int n, m; double c[500009], d[500009], deq[1000009]; vector slide_max(vector&x, int r) { vector F; int s = 0, t = 0; for (int i = 0; i < x.size(); i++)deq[i] = 0; for (int i = 0; i < x.size(); i++) { while (s < t && x[deq[t - 1]] <= x[i]) t--; deq[t++] = i; if (i - r + 1 >= 0) { F.emplace_back(x[deq[s]]); if (deq[s] == i - r + 1) s++; } } return F; } bool solve(double p) { for (int i = 0; i < n; i++) d[i] = c[i] - p; for (int i = 1; i < n; i++) d[i] += d[i - 1]; vectorV; for (int i = 0; i < n * 2; i++) { V.push_back(d[i%n] + d[n - 1] * (i / n)); } vectorW = slide_max(V, n - m); for (int i = 0; i < n; i++) { if (W[i + m] >= d[i])return true; } return false; } int main() { cin >> n >> m; string S; cin >> S; for (int i = 0; i < n; i++) { char e = S[i]; if (e == '0')c[i] = 0.0; if (e == '1')c[i] = 1.0; } double L = 0, R = 1, M; for (int i = 0; i < 30; i++) { M = (L + R) / 2.0; bool I = solve(M); if (I == true)L = M; else R = M; } printf("%.12Lf\n", M); return 0; }