#include using namespace std; using ld = long double; template class matrix { vector> dat; public: matrix(int row) : dat(row, vector(1)) {} matrix(int row, int col) : dat(row, vector(col)) {} matrix(int row, int col, const T& id) : dat(row, vector(col, id)) {} matrix(const vector>& v) : dat(v) {} matrix(const vector& v) : dat(v.size(), vector(1)) { for (int i = 0; i < (int)v.size(); ++i) dat[i][0] = v[i]; } explicit operator vector>() const { return dat; } int row_size() const { return dat.size(); } int col_size() const { return dat[0].size(); } matrix& operator+=(const matrix& that) { int row = row_size(), col = col_size(); assert(row_size() == that.row_size() && col_size() == that.col_size()); for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] += that[i][j]; return *this; } matrix& operator-=(const matrix& that) { int row = row_size(), col = col_size(); assert(row_size() == that.row_size() && col_size() == that.col_size()); for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] -= that[i][j]; return *this; } matrix& operator*=(const T& that) { int row = row_size(), col = col_size(); for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] *= that; return *this; } matrix& operator/=(const T& that) { int row = row_size(), col = col_size(); for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] /= that; return *this; } matrix operator*(const matrix& that) const { int x = row_size(), y = col_size(), z = that.col_size(); assert(col_size() == that.row_size()); matrix res(x, z); for (int i = 0; i < x; ++i) { for (int j = 0; j < y; ++j) { for (int k = 0; k < z; ++k) { res[i][k] += dat[i][j] * that[j][k]; } } } return res; } matrix& operator*=(const matrix& that) { return *this = *this * that; } vector& operator[](size_t i) & { return dat[i]; } const vector& operator[](size_t i) const& { return dat[i]; } vector operator[](size_t i) const&& { return move(dat[i]); } T& get(int i, int j) & { assert(0 <= i && i < row_size()); assert(0 <= j && j < col_size()); return dat[i][j]; } const T& get(int i, int j) const& { assert(0 <= i && i < row_size()); assert(0 <= j && j < col_size()); return dat[i][j]; } T get(int i, int j) const&& { assert(0 <= i && i < row_size()); assert(0 <= j && j < col_size()); return move(dat[i][j]); } matrix transpose() const { int row = row_size(), col = col_size(); matrix res(col, row); for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) res[j][i] = dat[i][j]; return res; } }; template matrix operator+(const matrix& a, const matrix& b) { return matrix(a) += b; } template matrix operator-(const matrix& a, const matrix& b) { return matrix(a) -= b; } template matrix operator*(const matrix& a, const T& b) { return matrix(a) *= b; } template matrix operator*(const T& a, const matrix& b) { return matrix(b) *= a; } template matrix operator/(const matrix& a, const T& b) { return matrix(a) /= b; } template matrix identity_matrix(int n) { matrix a(n, n); for (int i = 0; i < n; i++) a[i][i] = T(1); return a; } template matrix pow(const matrix& a, long long b) { const int n = a.row_size(); assert(a.row_size() == a.col_size() && 0 <= b); matrix res = identity_matrix(n), x(a); while (true) { if (b & 1LL) res *= x; if (!(b >>= 1LL)) break; x *= x; } return res; } const ld eps = 1e-10; template bool is_zero(T val) { return val == T(0); } template <> bool is_zero(ld val) { return std::abs(val) < eps; } template vector gauss_jordan(const matrix& A, const vector& b) { const int n = A.row_size(); matrix B(n, n + 1); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) B[i][j] = A[i][j]; B[i][n] = b[i]; } for (int i = 0; i < n; ++i) { int pivot = i; for (int j = i; j < n; ++j) { if (std::abs(B[j][i]) > std::abs(B[pivot][i])) pivot = j; if (!is_zero(B[j][i])) pivot = j; } if (i != pivot) swap(B[i], B[pivot]); if (is_zero(B[i][i])) return vector(); // no solution for (int j = i + 1; j <= n; ++j) B[i][j] /= B[i][i]; for (int j = 0; j < n; ++j) { if (i == j) continue; for (int k = i + 1; k <= n; ++k) B[j][k] -= B[j][i] * B[i][k]; } } vector x(n); for (int i = 0; i < n; ++i) x[i] = B[i][n]; return x; } int main() { cout << fixed << setprecision(10); int n, m; cin >> n >> m; vector c(n); for (int i = 1; i < n - 1; i++) { cin >> c[i]; } reverse(c.begin(), c.end()); matrix mat(m, m); vector b(m); mat[0][0] = 1; b[0] = 0; for (int i = 1; i < m; i++) { mat[i][i] = -1; int x = m - (i * 2 <= m); b[i] += (ld)-c[i] * m / x; for (int j = 1; j <= m; j++) { int p = abs(i - j); if (p == i) continue; mat[i][p] += (ld)1 / x; } } vector dp1 = gauss_jordan(mat, b); assert(!dp1.empty()); vector> dp(2, vector(n)); for (int i = 1; i < n; i++) { if (i < m) { dp[0][i] = dp1[i]; dp[1][i] = c[i]; } else { for (int j = 1; j <= m; j++) { dp[0][i] += (dp[0][i - j] + c[i]) / m; dp[1][i] += (dp[1][i - j] + c[i]) / m; } for (int j = 1; j <= m; j++) { dp[1][i] = min(dp[1][i], dp[0][i - j] + c[i]); } } } cout << dp[1][n - 1] << endl; return 0; }