#include #include #include #include #include #include // blue[l,r)/(r-l // blue[l,r)/(r-l) >= x // blue[l,r] >= x(r-l) // blue[r]-blue[l] >= xr - xl // blue[r]-xr >= blue[l] >= xl // r-l>=K int main() { int n, k; std::cin >> n >> k; std::string s; std::cin >> s; s += s; std::vector sum(n * 2 + 1); for (int i = 0; i < n * 2; i++) { sum[i + 1] = sum[i] + (s[i % n] == '1'); } double ok = 0; double ng = 1; for (int ii = 0; ii < 30; ii++) { double mid = (ok + ng) / 2; std::multiset ms; for (int i = k; i <= n; i++) { ms.insert(sum[i] - i * mid); } bool found = false; for (int i = 0; i < n; i++) { if (sum[i] - i * mid <= *ms.rbegin()) { found = true; } ms.erase(ms.find(sum[i + k] - mid * (i + k))); ms.insert(sum[i + n + 1] - mid * (i + n + 1)); } (found ? ok : ng) = mid; } printf("%.20f\n", ok); }