#include using namespace std; vector> reduce(vector> a) { int h = a.size(); int w = a[0].size(); int r = 0; for (int j = 0; j < w && r < h; j++) { int p = r; for (int i = r + 1; i < h; i++) { if (abs(a[i][j]) > abs(a[p][j])) { p = i; } } swap(a[p], a[r]); if (abs(a[r][j]) < 1e-8) { continue; } for (int ii = 0; ii < h; ii++) { if (ii != r) { double q = a[ii][j] / a[r][j]; for (int jj = 0; jj < w; jj++) { a[ii][jj] -= q * a[r][jj]; } } } double q = a[r][j]; for (int jj = 0; jj < w; jj++) { a[r][jj] /= q; } r++; } assert(r == h); return a; } int main() { int n, m; cin >> n >> m; vector c(n); for (int i = 1; i < n - 1; i++) { cin >> c[i]; } vector> a(n - 1, vector(n)); for (int i = 0; i < n - 1; i++) { a[i][i] = 1; for (int j = 1; j <= m; j++) { int ii = i + j; if (ii >= n) { ii -= n; } a[i][ii] -= 1.0 / m; a[i][n - 1] += c[ii] / m; } } a = reduce(a); vector dp(n); for (int i = n - 2 - m; i >= 0; i--) { double mini = 1e100; for (int j = 1; j <= m; j++) { dp[i] += (dp[i + j] + c[i + j]) / m; mini = min(mini, a[i + j][n - 1] + c[i + j]); } dp[i] = min(dp[i], mini); } printf("%.20f\n", dp[0]); }