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 (Python):
n,k=map(int,input().split())
P=[int(i) for i in input().split()]
ans=0
for i in range(k):
  ans+=(P[i]+1)/2
cur=ans
for i in range(k,n):
  cur+=(P[i]+1)/2
  cur-=(P[i-k]+1)/2
  if cur>ans:
    ans=cur
print(ans)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))

P = list(map(lambda x: (1+x)/2, p))

ans = sum(P[0:K])
temp = sum(P[0:K])
for i in range(N-K):
    temp = temp-P[i]+P[i+K]
    ans = max(ans, temp)
print(ans)

Solution (Python):
import itertools 
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = [ (i+1)/2 for i in A]
C = [0] + list(itertools.accumulate(B))
ans = 0
for i in range(n + 1 - k):
    ans = max(ans,C[i+k]-C[i])
print(ans)

Solution (Python):
n, k = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
for i in P[:k]:
  ans += (i+1)/2
temp = ans
for i in range(k, n):
  temp -= (P[i-k]+1)/2
  temp += (P[i]+1)/2
  ans = max(ans, temp)
print(ans)

Solution (Python):
def main():
    N, K = map( int, input().split())
    P = list( map( int, input().split()))
    now = sum(P[:K])
    ans = now
    for i in range(K,N):
        now -= P[i-K]
        now += P[i]
        if now > ans:
            ans = now
    print((ans+K)/2)
if __name__ == '__main__':
    main()

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = map(int, raw_input().split())
p = map(int, raw_input().split())
for i in range(N):
    p[i] += 1
    p[i] /= 2.0
S = 0.0
for i in range(K):
    S += p[i]
ans = S
for i in range(K, N):
    S += p[i]
    S -= p[i - K]
    ans = max(ans, S)
print "%.5f" % ans

Solution (Python):
N ,K = map(int,input().split())
P = list(map(int,input().split()))
A = P[:K]
a = sum(A)
max = a
for i in range(N-K):
    a = a-P[i]+P[i+K]
    if max <= a:
        max = a
print((max+K)/2.0)

Solution (Python):
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

s = 0
for i in range(K):
    s += A[i] + 1

ma = s
for i in range(K, N):
    s += A[i] + 1
    s -= A[i-K] + 1
    ma = max(ma, s)

print(ma / 2)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))

A = [(a + 1) / 2 for a in A]


Acum = [0] + list(accumulate(A))
answer = -1
for i in range(N + 1 - K):
    answer = max(answer, Acum[i + K] - Acum[i])
    
print(answer)

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n):
  p[i]/=2
s=t=sum(p[:k])
for i in range(k,n):
  t=t-p[i-k]+p[i]
  s=max(s,t)
print(s+k/2)

Solution (Python):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
t = [0] * N
for i in range(N):
  x = a[i]
  t[i] = (x + 1) / 2
s = sum(t[: K])
res = s + 0
for i in range(N - K):
  s -= t[i]
  s += t[i + K]
  res = max(res, s)
print(res)

Solution (Python):
n,k = map(int,input().split())
pl = list(map(int,input().split()))

import itertools
pl_ac = [0] + list(itertools.accumulate(pl))

ans = 0
for i in range(n-k+1):
    tmp = pl_ac[i+k] - pl_ac[i]
    ans = max(tmp, ans)
print((ans+k)/2)

Solution (Python):
import sys
readline = sys.stdin.readline

N, K = map(int, readline().split())
P = list(map(int, readline().split()))
AP = P[:]
for i in range(1, N):
    AP[i] += AP[i-1]
AP = [0] + AP
ans = 0
for st in range(N-K+1):
    en = st+K
    ans = max(ans, AP[en] - AP[st])

print((ans+K)/2)

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, p: "List[int]"):
    q = [(1 + v) / 2 for v in p]
    ret = 0
    s = sum(q[:K])
    l = 0
    for i in range(0, N - K):
        tmp = s - l
        ret = max(ret, tmp)
        l += q[i]
        s += q[i + K]
    ret = max(ret, s - l)
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(N, K, p)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    P = list(map(int, input().split()))

    A = [(1+p)/2 for p in P]
    A_cs = [0] * (N+1)
    for i in range(N):
        A_cs[i+1] = A_cs[i] + A[i]
    ans = 0
    for i in range(N-K+1):
        ans = max(ans, A_cs[i+K] - A_cs[i])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate

N, K = map(int, input().split())
ps = list(map(int, input().split()))

Es = [p*(p+1)/2/p for p in ps]

accEs = list(accumulate([0]+Es))

ans = 0
for i in range(N-K+1):
    e = accEs[i+K] - accEs[i]
    ans = max(ans, e)

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
p = LIST()

l = 0
r = K
ma = 0
tmp = sum(p[:K])
ma = tmp
for i in range(N-K):
	tmp = tmp - p[i] + p[i+K]
	if tmp > ma:
		ma = tmp
		l = i+1
		r = i+K+1


ans = 0

for i in range(l, r):
	ans += (p[i]+1)/2
print(ans)

Solution (Python):
def examA():
    S, T = LSI()
    A, B = LI()
    U = SI()
    if S==U:
        print(A-1,B)
    else:
        print(A,B-1)
    return

def examB():
    S = SI()
    N = len(S)
    ans = ""
    for i in range(N):
        ans += "x"
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
        if d[a]>=2:
            print("NO")
            return
    print("YES")
    return

def examD():
    N, K = LI()
    P = LI()
    S = [0]*(N+1)
    for i in range(N):
        S[i+1] = S[i]+(P[i]+1)/2
    ans = 0
    for i in range(N-K+1):
        cur = S[i+K]-S[i]
        ans = max(ans,cur)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Solution (Python):
n,k = map(int,input().split())
p =list(map(int,input().split()))
mx = 0
s = 0
for i in range(k):
    s+=p[i]
mx = s
for i in range(k,n):
    s+=p[i]
    s-=p[i-k]
    if s>mx:
        mx = s
print((mx+k)/2)

Solution (Python):


N,K=map(int,input().split())
P=list(map(int,input().split()))

for i in range(len(P)):
    P[i]=(1+P[i])/2



temp=sum(P[:K])
ans=temp
for i in range(N-K):
    temp+=(P[i+K]-P[i])
    ans=max(ans,temp)
    
print(ans)

Solution (Python):
n,k = map(int, input().split())
p = list(map(int, input().split()))
p = [(i+1)/2 for i in p]
cs = [0]
for i in p:
    cs.append(cs[-1]+i)
ma = 0
for i in range(n-k+1):
    if ma < cs[i+k]-cs[i]:
        ma = cs[i+k]-cs[i]

print(ma)

Solution (Python):


n, m = map(int,input().split())
da = list(map(int,input().split()))

now = 0
for i in range(m):
    now += da[i]/2 + 0.5
ans = now
for i in range(m,n):
    now -= da[i-m]/2 - da[i]/2
    ans = max(ans, now)
print(ans)

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=sum(p[:k])
ans=(c+k)/2
for i in range(k,n):
    c+=p[i]-p[i-k]
    ans=max(ans,(c+k)/2)
print(ans)

Solution (Python):
n,k = map(int,input().split())
p = list(map(int,input().split()))
data = [(x+1)/2 for x in p]

ans = sum(data[:k])
now = ans

for i in range(k,n):
    now += data[i]-data[i-k]
    ans = max(ans,now)

print(ans)

Solution (Python):
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    E = list(map(lambda x: (1+x)/2, P))
    tmp = sum(E[:K])
    ans = tmp
    for i in range(K, N):
        tmp += E[i] - E[i-K]
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


N,K = map(int,input().split())
A = list(map(int,input().split()))
def it():
    c = sum(A[:K])
    yield c
    for i in range(K,N):
        c += A[i]
        c -= A[i-K]
        yield c

print((max(it())+K)/2)

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [(p+1)/2 for p in P]
ans = s = sum(Q[:K])
for i in range(K, N):
    s += Q[i] - Q[i-K]
    ans = max(ans, s)
print(ans)

Solution (Python):
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

L = [0] * N

for i in range(N):
  L[i] = (1 + p[i]) / 2

ans = 0

k = 0
for i in range(K):
  k += L[i]

ans = k
for i in range(K, N):
  k += L[i] - L[i - K]
  ans = max(ans, k)

print(ans)

Solution (Python):
from itertools import accumulate as acc

N, K = map(int, input().split())
P = list(map(int, input().split()))

p = [(1+p_i)/2 for p_i in P]

l = [0] + list(acc(p))

max_num = 0
for i in range(N-K+1):
    s = l[i+K] - l[i]
    max_num = max(s, max_num)

print(max_num)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
S = [0]*(N-K+1)
for i in range(K):
    S[0]+=p[i]+1
for i in range(1, N-K+1):
    S[i] = S[i-1]+p[K+i-1]+1-(p[i-1]+1)
print(max(S)/2)

Solution (Python):
N,K=map(int,input().split())
P=list(map(int,input().split()))

V=[(1+p)/2 for p in P]

from itertools import accumulate

S=[0]+list(accumulate(V))

ANS=0
for i in range(K,N+1):
    ANS=max(ANS,S[i]-S[i-K])

print(ANS)

Solution (Python):
n,k = map(int, input().split())
exp = [(int(x)+1)/2 for x in input().split()]

tmp = sum(exp[:k])
ans = tmp

for i in range(k,n):
    tmp += exp[i]
    tmp -= exp[i-k]
    ans = max(ans,tmp)

print(ans)

Solution (Python):
N, K= map(int,input().split())
p = list(map(int,input().split()))

e = [(pi+1)/2 for pi in p]

f = sum(e[:K])
ans = f

for i in range(K,N):
    f = f - e[i-K] + e[i]
    ans = max(ans,f)

print(ans)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))

s = sum(p[:k])
s += k
s /= 2
ans = s

for i in range(n-k):
    s -= (p[i]+1)/2
    s += (p[i+k]+1)/2
    ans = max(ans, s)

print(ans)

Solution (Python):
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=float)

E = (A + 1) * 0.5
cumE = np.zeros(N + 1, dtype=float)
cumE[1:] = E.cumsum(axis=0)

ans = (cumE[K:] - cumE[:-K]).max()
print(ans)

Solution (Python):

n,k = map(int,input().split())
P = list(map(int,input().split()))
Q = []
for i in range(n):
    Q.append((P[i]-1)/2 + 1)
R = [Q[0]]
for i in range(1, n):
    R.append(R[-1] + Q[i])
l = 0
r = R[k-1]
ans = r-l
for i in range(n-k):
    ans = max(ans, R[k+i]-R[i])
print(ans)

Solution (Python):

import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, K: int, p: "List[int]"):

    acc = [0]+list(accumulate(p))
    m, mi = 0, 0
    for i in range(N-K+1):
        if acc[i+K]-acc[i] > m:
            m = acc[i+K]-acc[i]
            mi = i
    print((m+K)/2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(N, K, p)


if __name__ == '__main__':
    main()

Solution (Python):
N,K = map(int,input().split())

ans = 0

p = list(map(int,input().split()))

now = 0

for i in range(N):

    if i < K-1:
        now += (1+p[i])

    else:
        now += (1+p[i])

        ans = max(ans,now)

        now -= (1 + p[i-(K-1)])

print (ans / 2)

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [0]+list(accumulate((1+p)/2 for p in P))
print(max(Q[K+i]-Q[i] for i in range(N-K+1)))

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,k = nm()
p = [0] + nl()
for i in range(n):
    p[i+1] += p[i] + 1
ans = max(p[i+k] - p[i] for i in range(n+1-k))
print(ans/2)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n, k = na()
ps = na()

cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + ps[i]

mx = 0
for i in range(n-k+1):
    mx = max(mx, cum[i+k] - cum[i])
print("{:.14f}".format((mx + k) / 2))

Solution (Python):
n,k = map(int,input().split())
lis = list(map(int,input().split()))
for i in range(n):
    lis[i] = (lis[i]+1)/2
now = sum(lis[:k])
ans = now
for i in range(n-k):
    now -= lis[i]
    now += lis[i+k]
    ans = max(now,ans)
print(ans)

Solution (Python):
N,K = map(int,input().split())
P = list(map(int,input().split()))
Q = [(p+1)/2 for p in P]
c = [0]
for q in Q:
    c.append(c[-1] + q)

ans = 0
for i in range(K,N+1):
    ans = max(ans, c[i] - c[i-K])
print(ans)

Solution (Python):
N, K = map(int, raw_input().split())
p = map(int, raw_input().split())

s = sum(p[:K])
m = s
for i in range(K, N):
  s += p[i]
  s -= p[i-K]
  m = max(m, s)
print "%.10f"%((m+K)*.5)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
res = tmp
for i in range(n - k):
    tmp -= p[i]
    tmp += p[i + k]
    res = max(res, tmp)
print((res + k) / 2)

Solution (Python):
N,K=map(int,input().split())
p=[int(i) for i in input().split()]
q=[(i+1)/2 for i in p]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+q[i]
ans=0
for i in range(N-K+1):
    ans=max(ans,S[i+K]-S[i])
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
p = list(map(int, input().split()))
a = [(pi+1)/2 for pi in p]
acc = [0]

for ai in a:
    acc.append(acc[-1]+ai)
    
ans = 0

for i in range(N-K+1):
    ans = max(ans, acc[i+K]-acc[i])

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    p=list(map(int,input().split()))
    S=[0]*(N+1)
    for i in range(N):
        S[i+1]=S[i]+p[i]
    ans=float(0)
    for i in range(N-K+1):
        tmp=(S[i+K]-S[i]+K)/2
        ans=max(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
a = [(a[i]+1)/2 for i in range(n)]
acc = [0]+list(accumulate(a))
ans = 0
for i in range(n-k+1):
  ans = max(ans,acc[i+k]-acc[i])
print(ans)

Solution (Python):
N, K = map(int, input().split())
p = [int(i) for i in input().split()]

for i in range(N) :
  p[i] = p[i] * (p[i] + 1) // 2 / p[i]
  
p = [0] + p

for i in range(1, N + 1) :
  p[i] += p[i - 1]

ret = 0
for i in range(K, N + 1) :
  ret = max(ret, p[i] - p[i-K])
  
print(ret)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
q = [(x+1)/2 for x in p]
cur = sum(q[:k])
ans = cur
for i in range(k, n):
	cur = cur - q[i-k] + q[i]
	ans = max(ans, cur)
print(ans)

Solution (Python):



import sys
readline = sys.stdin.readline
read = sys.stdin.read


n,k,*p = [int(i) for i in read().split()]


p = [(1+i) for i in p]


m = a = sum(p[:k])
for i in range(k,n):
    a += p[i]
    a -= p[i-k]
    m = max(m,a)

print(m/2)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()

input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0

n,k=LI()
a=[(1+i)/2 for i in LI()]
ac=[0]
for i in range(n):
    ac+=[ac[-1]+a[i]]

for i in range(n-k+1):
    ans=max(ac[i+k]-ac[i],ans)

print(ans)