#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 < 20; ii++) { double mid = (ok + ng) / 2; std::deque> deq; for (int i = k; i < n; i++) { deq.emplace_back(sum[i] - i * mid, i); } bool found = false; for (int i = 0; i < n; i++) { while (!deq.empty() && deq.front().second < i + k) deq.pop_front(); while (!deq.empty() && deq.back().first < sum[i + n + 1] - mid * (i + n + 1)) deq.pop_back(); deq.emplace_back(sum[i + n + 1] - mid * (i + n + 1), i + n + 1); if (sum[i] - i * mid <= deq.front().first) { found = true; } } (found ? ok : ng) = mid; } printf("%.20f\n", ok); }