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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var P = cin.ReadIntArray(2);
            var N = P[0];var K = P[1];
            P = cin.ReadIntArray(N);
            var maxima = new int[N];
            maxima[0] = (P[0] + 1);
            for(int i = 1; i < N; i++) {
                maxima[i] = maxima[i - 1] + (P[i] + 1);
                if(i >= K)
                    maxima[i] -= P[i - K]+1;
            }
            double res = (double)maxima.Skip(K).Max()/2;
            Console.WriteLine(res);
        }
    }

    class PriorityQueue<T> where T: IComparable<T> {
        List<T> body = new List<T>();
        bool isRootMaximum { get; }
        public PriorityQueue(bool maxTop = true) { isRootMaximum = maxTop; }
        //suppose Me>Her if isRootMaximum
        int Compare(T Me, T Her) => isRootMaximum ? Me.CompareTo(Her) : -(Me.CompareTo(Her));
        int Compare(int x, int y) => Compare(body[x], body[y]);
        void Swap(int x, int y) { T tmp = body[x]; body[x] = body[y]; body[y] = tmp; }
        public void Push(T elem) {
            body.Add(elem);
            //the parent of n-th element is the ((n+1)>>1)-1-th
            int j = lastIndex;
            while(j > 0) {
                int parent = ((j + 1) >> 1) - 1;
                if(Compare(parent, j) < 0)
                    Swap(parent, j);
                else break;
                j = parent;
            }
        }
        public T Pop() {
            T top = body[0];
            Swap(0, lastIndex);
            body.RemoveAt(lastIndex);
            var newComer = 0;
            while(newComer < length) {
                var leftChild = ((newComer + 1) << 1) - 1;
                if(leftChild >= length) break;
                var toSwap = leftChild;
                var rightChild = leftChild + 1;
                if(rightChild < length && Compare(leftChild, rightChild) < 0)
                    toSwap = rightChild;
                if(Compare(newComer, toSwap) < 0)
                    Swap(toSwap, newComer);
                else break;
                newComer = toSwap;
            }
            return top;
        }
        T Top { get { return body[0]; } }
        int length { get { return body.Count(); } }
        int lastIndex{ get { return body.Count() - 1; } }
        public string Emit() { return body.ToArray().Join(","); }
    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}