#include #include typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define incII(i, l, r) for(int i = (l) ; i <= (r); i++) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define decII(i, l, r) for(int i = (r) ; i >= (l); i--) #define inc( i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec( i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) template void swap(T & x, T & y) { T t = x; x = y; y = t; return; } template T abs(T x) { return (0 <= x ? x : -x); } template T max(T a, T b) { return (b <= a ? a : b); } template T min(T a, T b) { return (a <= b ? a : b); } template bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } } template bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- int n, m; double c[100], dp[100][3]; const double INF = 1e15; int main() { scanf("%d%d", &n, &m); inc1(i, n - 2) { scanf("%lf", &c[i]); } c[0] = c[n - 1] = 0.0; inc1(i, m) { dp[n - i][0] = dp[n - i][1] = c[n - i]; } inc(q, 44) { incII(i, n - m, n - 2) { double sum = 0.0; inc1(j, m) { int k = i + j; sum += dp[k < n ? k : (n - 1) - (k - (n - 1))][1]; } dp[i][2] = dp[i][0] + sum / m; } incII(i, n - m, n - 2) { dp[i][1] = dp[i][2]; } } dec(i, n - m) { double sum0 = 0.0, sum1 = 0.0, min1 = INF; inc1(j, m) { sum0 += dp[i + j][0]; sum1 += dp[i + j][1]; setmin(min1, dp[i + j][1]); } dp[i][0] = c[i] + min(sum0 / m, min1); dp[i][1] = c[i] + sum1 / m; } printf("%.12f\n", dp[0][0]); return 0; }