Problem:
Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

// 最大公約数
fn gcd(a: u64, b: u64) -> u64 {
    let mut aa: u64 = if a > b { a } else { b };
    let mut bb: u64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

// 最小公倍数
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

// DFS,BFS
fn BFS() {
    let mut searchResult = vec![vec![MAX; 100]; 100];
    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    q.push_front((0, 0));
    searchResult[0][0] = 0;

    let moves = [(1, 0), (-1, 0), (0, 1), (0, -1)];

    while !q.is_empty() {
        let pos = q.pop_back().unwrap(); // これがpop_frontならstackになって深さ優先になる
        for m in moves.iter() {
            let dx: i64 = pos.0 as i64 + m.0;
            let dy: i64 = pos.1 as i64 + m.1;
            if dx >= 0
                && dx < 100
                && dy >= 0
                && dy < 100
                && searchResult[dx as usize][dy as usize] == MAX
            {
                q.push_front((dx as usize, dy as usize));
                searchResult[dx as usize][dy as usize] = searchResult[pos.0][pos.1] + 1;
            }
        }
    }
}

// 文字列操作

const LARGE_PRIME: u64 = 1_000_000_007;

fn inverse_mod(element: u64, modulo: u64) -> u64 {
    // フェルマーの小定理からpが素数なら a^(p-1) = 1
    // よってa*a^(p-2) = 1 より a^(p-2)がaの逆元

    fn power(base: u64, exp: u64, modulo: u64) -> u64 {
        if exp == 0 {
            return 1;
        } else if exp & 1 == 0 {
            return (power(base, exp / 2, modulo) % modulo).pow(2) % modulo;
        } else {
            return power(base, exp - 1, modulo) % modulo * base % modulo;
        }
    }

    power(element, modulo - 2, modulo) % modulo
}

fn combination_mod(m: u64, n: u64, modulo: u64) -> u64 {
    // m C n = m! / ( n! * (m - n)! )
    //       = m*(m-1)*(m-2)*...*(m-n+1)/n!
    //       = m*(m-1)*(m-2)*...*(m-n+1) * (n!)^-1

    let mut numerator = 1;
    for i in 0..n {
        numerator *= m - i;
        numerator %= modulo;
    }

    // (m-n)!
    let mut element = 1;
    for j in 1..(n + 1) {
        element *= j;
        element %= modulo;
    }

    numerator * inverse_mod(element, modulo) % modulo
}

fn solve() {
    input! {
        n: usize,
        k: usize,
        p: [usize; n]
    }

    let mut exp = vec![0.0; 1001];
    for i in 1..1001 {
        exp[i] = (exp[i - 1] + i as f64);
    }

    for i in 1..1001 {
        exp[i] = exp[i] / i as f64;
    }

    let mut max = 0.0;

    let mut cumulative_sum = vec![0.0; n];

    cumulative_sum[0] = exp[p[0]];

    for i in 1..n {
        cumulative_sum[i] = cumulative_sum[i - 1] + exp[p[i]];
    }

    for i in k..n {
        let mut total = cumulative_sum[i] - cumulative_sum[i - k];

        if total > max {
            max = total;
        }
    }

    println!("{}", max);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}