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_n = [int(i) for i in input().split()]

def expected(x):
    return (x+1)/2

def test3():
    e_n = list(map(expected, p_n))
    s_n = []
    for i, e in enumerate(e_n):
        if i == 0:
            s_n.append(e)
            continue
        s_n.append(s_n[i-1] + e)
    result = []
    result.append(s_n[k-1])
    for i in range(len(s_n)):
        if i+k >= n:
            continue
        result.append(s_n[i+k]-s_n[i])
    print(max(result))      
test3()

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

max_value = sum((p_i + 1) / 2 for p_i in p[:k])
cur = max_value
for i in range(k, n):
    cur += ((p[i] + 1) / 2 - (p[i-k] + 1) / 2)
    max_value = max(max_value, cur)
print(max_value)

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

max_value = sum((p_i + 1) / 2 for p_i in p[:k])
cur = max_value
for i in range(k, n):
    cur += ((p[i] + 1) / 2 - (p[i-k] + 1) / 2)
    max_value = max(max_value, cur)
print(max_value)

Solution (Python):
import numpy as np

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    
    e = [(p[j-1]+1)/2.for j in range(1, n+1)]
    
    c_s = np.cumsum(e)
    
    s = c_s[k-1:] - np.r_[[0],c_s[:n-k]]
    
    ans = max(s)

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    e = [(p[j-1]+1)/2.for j in range(1, n+1)]
    s = [sum(e[:k])]
    for i in range(1, n-k+1):
        s.append(s[-1]-e[i-1]+e[k+i-1])
    ans = max(s)
    print(ans)

if __name__ == "__main__":
    main()

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

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

def kitaiti(num):
    result = (num+1)*num/(num*2)
    return result
r = [kitaiti(p[i]) for i in range(n)]

result = [sum(r[:k])]
for i in range(k, n):
    result.append(result[-1]-r[i-k]+r[i])
print(max(result))

Solution (Python):

import numpy as np
from collections import deque

N, K = map(int, input().split())
p = [float(x) for x in input().split()]
p = np.array(p)

p = (1.+p)/2.
q = deque()

ans = 0.
tmp = 0.
for i in range(len(p)) : 
    q.append(p[i])
    tmp += p[i]
    if ( len(q) == K ) : 
        ans = max(ans, tmp)
        tmp -= q.popleft()

print("{:.10f}".format(ans))

Solution (Python):
n,k = map(int,input().split())
p = list(map(int,input().split()))
maxn = 0
sum = 0
for i in range(n-k+1):
	if i == 0:
		for j in range(k):
			sum += p[j]
		maxn = sum
	else:
		sum -= p[i-1]
		sum += p[i+k-1]
		if maxn < sum:
			maxn = sum
print(0.5*(maxn+k))

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

m = max(p)
l = [0]
for i in range(1,m + 1):
    l.append(l[-1] + i)
for i in range(1,len(l)):
    l[i]/=i
for i in range(n):
    p[i] = l[p[i]]


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

ans = 0
for i in range(len(p) - k):
    ans = max(ans,p[i + k] - p[i])

print(ans)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
 
exp = []
sum_list = []
result_list = []
result = 0
count = 0
tmp = 0
for i in range(N):
    if count < K-1:
        a = (p[i]+1)/2
        exp.append(a)
        tmp += a
    else:
        a = (p[i]+1)/2
        exp.append(a)
        tmp += a
        sum_list.append(tmp)
        tmp -= exp[count-K+1]
    count += 1

print(max(sum_list))

Solution (Python):
from decimal import*
from fractions import*
import math
import functools


import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines 

def cmp(a,b):
    if(a<b):
        return 1
    elif(a==b):
        return 0
    else:
        return -1 

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

lit=[]
for num in p:
    Sum=num*(num+1)/2
    lit.append(Sum/num)
Sum=0
ans=0
for i in range(k):
    Sum+=lit[i]
ans=Sum
for i in range(k,n):
    Sum-=lit[i-k]
    Sum+=lit[i]
    ans=max(ans,Sum)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines  

from itertools import accumulate

N, K = map(int, input().split())
P = list(map(int, input().split()))
Pcum = list(accumulate([0] + [(1+p)/2 for p in P]))

ans = max(right - left for left, right in zip(Pcum, Pcum[K:]))
print(ans)

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

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

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

s = 0
for i in range(K):
    s += p[i]
ans = (K+s)/2

for i in range(K, N):
    s += p[i]
    s -= p[i-K]
    ans = max(ans, (K+s)/2)

print(ans)

Solution (Python):
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]
res=0
for i in range(n-k+1):
    res=max(res,s[i+k]-s[i])
print((res+k)/2)

Solution (Python):
import numpy as np

N, K = map(int, input().split())
p = [int(i) for i in input().split()]
p = np.array(p)
p = (p + 1)/2
p = np.cumsum(np.insert(p, 0, 0))
stride = K
print(np.max(p[stride:] - p[:-stride]))

Solution (Python):
def exp(x):
  return (1+x) / 2

n, k = map(int, input().split())
p = list(map(int, input().split()))
  
sum = 0
for i in range(k):
  sum += exp(p[i])
max = sum

for i in range(n-k):
  sum += exp(p[i+k]) - exp(p[i])
  if max < sum:
    max = sum

print(max)

Solution (Python):
N,K = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
E = [p*(p+1)//2/p for p in P]
cE = [E[0]]
for i in range(1,N): cE.append(cE[-1]+E[i])
cE = [0]+cE
sE = []
i = 0
while i+K < len(cE):
    sE.append(cE[i+K]-cE[i])
    i += 1
print(max(sE))

Solution (Python):
n,k = map(int, input().split())
p = list(map(int, input().split()))
def expected_value(p):
  E = []
  for i in p:
    E.append(float((i+1)/2))
  return E
def cumulative_sum(E, n):
  s = []
  for i in range(n):
    if i == 0:
      s.append(0)
    s.append(s[i]+E[i])
  return s
def max_search(k,n,p):
  ans = []
  E = expected_value(p)
  S = cumulative_sum(E, n)
  for i in range(int(n-k+1)):
    ans.append(S[i+k] - S[i])
  return max(ans)
print(max_search(k,n,p))

Solution (Python):
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=0
for i in range(n-k+1):
   ans=max(ans,S[i+k]-S[i])
print((ans+k)/2)

Solution (Python):
import numpy as np

n,k = map(int, input().split())
p = np.array(list(map(int, input().split())))

exp = (p + 1) / 2
max_sum_exp = sum(exp[0:k])
sum_exp = max_sum_exp
for i in range(n-k):
    sum_exp = sum_exp + exp[k+i] - exp[i]
    max_sum_exp = max(sum_exp, max_sum_exp)

print(max_sum_exp)

Solution (Python):
n,k,*p=map(int,open(0).read().split())
s=sum(p[:k])  
l=[s]
for i in range(k,n):
  s=s-p[i-k]+p[i]
  l.append(s)
print((max(l)+k)/2)

Solution (Python):
from math import ceil
N, K = map(int, input().split())
P = list(map(int, input().split()))
E = [0]
E.append(sum([i for i in range(1, P[0] + 1)])/P[0])
for i in range(1,N):
    p = P[i]
    E.append(E[i] + ((1+p) / 2))
r = K
ans = 0
while r < N + 1:
    ans = max(ans, E[r] - E[r - K])
    r += 1
print(ans)

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

ans = sum(p[0:k])
tmp = sum(p[0:k])

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

print(ans)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
ans = [tmp]
if n == k:
    ans_mae = ans[0]
    print((ans_mae+k)/2)
else:
    for i in range(1,n-k+1):
        tmp = tmp - p[i-1] + p[i+k-1]
        ans.append(tmp)
    print((max(ans)+k)/2)

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

    ans = 0.0
    count = 0
    tmp = 0.0
    for i in range(n):
        if count == k:
            tmp = tmp - (1.0 + float(p[i-k])) / 2.0 + (1.0 + float(p[i])) / 2.0
            if tmp > ans:
                ans = tmp
        else:
            tmp += (1.0 + float(p[i])) / 2.0
            ans = tmp
            count += 1

    print(ans)

Solution (Python):
n, k = map(int, input().split())
p = [(1 + int(x)) / 2 for x in input().split()]
a_idx, l, r = 0, 0, 0
for i in range(1, n - k + 1):
    l += p[i - 1]
    r += p[i + k - 1]
    if r > l:
        a_idx, l, r = i, 0, 0
print(sum(p[a_idx:a_idx + k]))

Solution (Python):
n, k = list(map(int,input().split()))
p = list(map(int,input().split()))
p = list(map(lambda x: (x+1)/2, p))

temp = 0

for i in range(k):
    temp += p[i]

ans = temp

for i in range(1, n-k+1):
    temp -= p[i-1]
    temp += p[i+k-1]
    if temp > ans:
        ans = temp

print(ans)

Solution (Python):
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    ls = [0] * (n + 1)
    tm = 0
    for i, v in enumerate(a):
        ls[i + 1] = (((1 + v) * v) // 2) / v
    ls = list(itertools.accumulate(ls))
    for i in range(k, n + 1):
        tm = max(tm, ls[i] - ls[i-k])
    print(tm)


if __name__ == '__main__':
    solve()

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

Solution (Python):
N,K = map(int, input().split())
P = [int(i) for i in input().split()]
total, maxS = 0, 0
S = [0]
for p in P:
    total += p*(p+1)/2/p
    S.append(total)

for i in range(N-K+1):
    if maxS < S[i+K]-S[i]:
        maxS = S[i+K]-S[i]
print(maxS)

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

    P_e = []
    for p in P:
        P_e.append((1 + p)/2)

    P_sum = [0]
    tmp = 0
    for i in range(N):
        tmp += P_e[i]
        P_sum.append(tmp)

    max = 0
    for i in range(K, N+1):
        tmp = P_sum[i] - P_sum[i-K]
        if tmp > max:
            max = tmp

    print(max)
    return 0
if __name__ == '__main__':
    main()

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

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

s = 0
a = sum(p[:k])
for i in range(n-k+1):
    if i != 0:
        a = a-p[i-1]+p[i+k-1]
    if a > s:
        s = a
        
print((s+k)/2)

Solution (Python):
from functools import reduce

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

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(max_mean, cur)
print(max_mean)

Solution (Python):
from functools import reduce

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

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += (0.5 * (p[i] - p[i - k]))
    max_mean = max(cur, max_mean)
print(max_mean)

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

lastSum = sum(inList[0: K])
maxNum = lastSum

for indx in range(1, N - (K - 1)):
  maxNum = max(lastSum - inList[indx-1] + inList[indx+K-1], maxNum)
  lastSum = lastSum - inList[indx-1] + inList[indx+K-1]

print((maxNum + K) / 2)

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


E=[]
for i in range(0,N):
    E.append((1+P[i])/2)
    
wa=[]
wa.append(sum(E[0:K]))
for j in range(1, N-K+1):
    wa.append(wa[j-1] - E[j-1] + E[j+K-1])
print(max(wa))

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

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

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

tmp = sum(p[:K])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp

print((max+K)/2)

Solution (Python):
import numpy as np

N, K= map(int, input().split())
p = np.array(list(map(int, input().split())))

tmp = np.sum(p[:K])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp

print((max+K)/2)

Solution (Python):
def all_sum(val):
    sum = 0
    for i in range(val):
        sum = sum + i + 1
    return sum / val


[n, k] = input().split()

p = input().split()

k = int(k)
n = int(n)
p = [int(i) for i in p]

total = 0
max_total = 0
for i in range(k):
    total = total + p[i]
max_total = total
max_ind = 0

for i in range(n - k):
    total = total - p[i] + p[i + k]
    if(max_total < total):
        max_total = total
        max_ind = i + 1
ans = 0
for i in range(k):
    ans = ans + all_sum(p[i + max_ind])

print("{:.8f}".format(ans))

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

Solution (Python):
import numpy as np
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[0]
def ex(A):
  return (1+A)/2.0
for i in range(N):
  Q.append(ex(P[i]))
Q=np.array(Q)
R=Q.cumsum()
ans=0
for i in range(K,N+1):
  S=R[i]-R[i-K]
  if ans<S:
    ans=S
print(ans)

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
lis = [0]*N
for i in range(N):
    if p[i]%2 == 1:
        lis[i] = p[i]//2+1
    else:
        lis[i] = (p[i]+1)/2
ans = sum(lis[:K])
temp = sum(lis[:K])
for j in range(N-K):
    temp -= lis[j]
    temp += lis[j+K]
    if temp > ans:
        ans = temp
print(ans)

Solution (Python):
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
cums = [0]*1001
cnt = 0
for i in range(1001):
    cnt += i
    cums[i] = cnt

p_new = [cums[j]/j for j in P]
sp = sum(p_new[0:K])

ans = []
ans.append(sp)
cnt = 0
for k in range(K,N):
    sp = sp + p_new[k]
    sp = sp - p_new[cnt]
    cnt += 1
    ans.append(sp)

print(max(ans))

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

for i in range(N):
    P.append((p[i] + 1)/2)
    temp = temp + P[i]
    P_S.append(temp)
for i in range(K,N+1):
    ans_list.append(P_S[i] - P_S[i - K])

print(max(ans_list))

Solution (Python):


n,k=list(map(int,input().split()))
dices = list(map(float,input().split()))
expected = []
answer = 0
i = 0
j = 0
sumOfValue = 0
expected.append(i)

for eyes in dices:
    i = (eyes+1)/2
    j = j + i
    expected.append(j)

for t in range(n-k+1):
    sumOfValue = expected[t+k] - expected[t]
    if(answer <= sumOfValue):
        answer = sumOfValue
print(answer)

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

print(max(ans))

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

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

Solution (Python):
def dice_in_line():
    N,K=map(int,input().split())
    p_n=list(map(int,input().split()))
    max=x=sum(p_n[:K])
    for i in range(N-K):
        x+=(p_n[K+i]-p_n[i])
        if max<x:
            max=x
    print((max+K)/2)

dice_in_line()

Solution (Python):


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


max = x = sum(s[:K])
for i in range(N - K):
    x += (s[K + i] - s[i])
    if max < x:
        max = x


print((max + K) / 2)

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

Solution (Python):
N, K = map(int,input().split())
l = list(map(int, input().split()))
c = sum(l[0:K])
ans = c
for i in range(N-K):
  c = c - l[i] + l[i + K]
  if c > ans:
    ans = c
print((ans+K)/2)

Solution (Python):


def main():
    n, k = map(int, input().split())
    pi = list(map(int, input().split()))
    kitai = [(x + 1) * 0.5 for x in pi]
    kitai_acc = [0]  
    for i in range(n):
        kitai_acc.append(kitai_acc[-1] + kitai[i])
    res = 0
    for i in range(n + 1 - k):
        x = kitai_acc[i + k] - kitai_acc[i]
        res = max(res, x)
    print(res)

main()

Solution (Python):
import numpy as np
N, K = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
ex = [i + 1 for i in p]
ans = sum(ex[0: K])
max_ans = ans
for i in range(K, N):
    ans += ex[i] - ex[i - K]
    max_ans = max(ans, max_ans)
print(max_ans / 2.0)

Solution (Python):
n,k = map(int, input().split())
p = [int(e) for e in input().split()]
s = sum(p[0:k])
max = s
for i in range(n-k):
  s = s - p[i] + p[i+k]
  if max < s:
    max = s
    
ex = (max+k)/2.0
print(ex)

Solution (Python):
a, b = map(int, input().split())
c = list(map(int,input().split()))

x = [(e + 1) / 2 for e in c]

t = sum(x[0:b])
res = t
for i in range(a - b):
  t -= x[i]
  t += x[i+b]
  res = max(res,t)

print('{:.12f}'.format(res))

Solution (Python):
n, k = map(int, input().split())
a = [int(i) for i in input().split(" ")]
sums = [sum(a[:k])] + [0 for i in range(n-k)]
for i in range(1, n-k+1):
    sums[i] = sums[i-1]-a[i-1]+a[i+k-1]
print((max(sums)+k)/2)

Solution (Python):
import sys
def main():
    l= sys.stdin.readline()
    N, K = map(int, l.split())
    
    l = sys.stdin.readline()
    nums = list(map(lambda a:(int(a)+1)/2.0, l.split()))
    
    M = sum(nums[:K])
    mx = M
    for i in range(K, len(nums)):
        
        M = M - nums[i-K] + nums[i]

        if M > mx:
            mx = M
        
    return mx
if __name__ == "__main__":
    print(main())

Solution (Python):
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
p_array = list(map(int,input().split()))

sum_max = sum(p_array[:K])
now_sum = sum_max
for i in range(1,N-K+1):
    now_sum -= p_array[i-1]
    now_sum += p_array[i+K-1]
    if now_sum > sum_max:
        sum_max = now_sum
    
print((K+sum_max)/2)

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

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

Solution (Python):
N,K=map(int,input().split())
lp=list(map(int,input().split()))
maxsum=sum(lp[:K])
befsum=maxsum
for i in range(1,N-K+1):
    tmpsum=befsum-lp[i-1]+lp[i+K-1]
    if tmpsum>maxsum:
        maxsum=tmpsum
    befsum=tmpsum
print((maxsum+K)/2)

Solution (Python):
def main():

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

if __name__ == "__main__":
    main()

Solution (Python):
n, k = (int(x) for x in input().split())
seq = [int(x) for x in input().split()]

ans = 0
for i in range(k):
    ans += 1/2*(2+(seq[i]-1)) 
score = ans
for i in range(n-k):
  score -= 1/2*(2+(seq[i]-1)) 
  score += 1/2*(2+(seq[i+k]-1)) 
  ans = max(ans, score)
  
print(round(ans, 9))

Solution (Python):
from itertools import accumulate
n,k=map(int,input().split())
a=list(map(int, input().split()))
b = [0] + a
b = list(accumulate(b))

ans = []
for i in range(n-k+1):
    ans.append(b[i+k]-b[i])
index = ans.index(max(ans))
a=a[index:index+k]
total=0
for i in a:
  total+=(1+i)/2
print(total)

Solution (Python):
r=input().strip().split()
N=int(r[0])
a=int(r[1])
z=input().strip().split()
s=0
for p in range (a):
    s+=(1+int(z[p]))/2
maximum=s

for j in range (0,N-a):
  s-=(1+int(z[j]))/2
  s+=(1+int(z[j+a]))/2
  if s>maximum:
    maximum=s

print(maximum)

Solution (Python):
import itertools as it
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

s = list(it.accumulate(p))
ss = [s[k-1]]
for i in range(k, n):
    ss.append(s[i] - s[i-k])
    
ans = max(ss)
print((ans+k)/2)

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

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

ans = 0
cumlative = []
for i in range(N):
	if i == 0:
		cumlative.append(ave[i])
	else:
		cumlative.append(cumlative[i-1]+ave[i])
	
if N == K:
	ans = cumlative[N-1]
else:
	for i in range(N-K):
		ans = max(cumlative[i+K] - cumlative[i],ans)

print(ans)

Solution (Python):
from collections import deque
n, k = map(int, input().split())
p = deque(map(int, input().split()))

adjacent = deque()
for i in range(k):
    adjacent.append(p.pop())

ans = sum(adjacent)
count = ans

while p:
    pp = p.pop()
    count -= adjacent.popleft()
    count += pp
    adjacent.append(pp)
    ans = max(ans, count)

print((ans + k) / 2)

Solution (Python):
from collections import deque
n, k = map(int, input().split())
p = deque(map(int, input().split()))

adjacent = deque()
for i in range(k):
    adjacent.append(p.popleft())

ans = sum(adjacent)
count = ans

while p:
    pp = p.popleft()
    count -= adjacent.popleft()
    count += pp
    adjacent.append(pp)
    ans = max(ans, count)

print((ans + k) / 2)

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

ruisekiwa=[0]

for i in range(N):
    ruisekiwa.append(ruisekiwa[i]+(1+p[i])/2)

max_value=0
for i in range(N-K+1):
    tmp=ruisekiwa[i+K]- ruisekiwa[i]
    if(max_value < tmp):
        max_value=tmp
print(max_value)

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

S=[0]
for i in range(n):
   S.append(S[i]+P[i])
ans=0
for j in range(n-k+1):
   ans=max(ans,(S[j+k]-S[j]))

print((ans+k)/2)

Solution (Python):
N,K = list(map(int,input().strip().split()))
P = list(map(int,input().strip().split()))
def find(P,K):
    temp = 0
    MAX = 0
    for i in range(K):
        temp += (P[i]+1)/2
    MAX = max(MAX,temp)
    for i in range(K,len(P)):
        temp -= (P[i-K]+1)/2
        temp += (P[i]+1)/2
        MAX = max(MAX,temp)
    return MAX
print(find(P,K))

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

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

Solution (Python):

import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)












Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]
print(length_K_sums.max() / 2)

Solution (Python):

import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)

"""
ans = 0

for num in range(len(p)):
    tmp = p[num:num+K].sum()
    if ans < tmp:
        ans = tmp

print(float(ans))

"""


Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]
print(length_K_sums.max() / 2)

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

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

def exp(n):
    return n*0.5 + 0.5

ans = 0
for i in range(k):
    ans += p[i]
    tmp = ans

for i in range(n-k):
    tmp = tmp - p[i] + p[i+k]
    if tmp > ans:
        ans = tmp

print(ans*0.5 + k*0.5)

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

cum_E = [0] * (N+1)
for i in range(N):
  cum_E[i+1] = cum_E[i] + (A[i]+1)/2
  
k_cum_E = [0] * (N-K+1)
for i in range(N-K+1):
  k_cum_E[i] = cum_E[i+K] - cum_E[i]

print(max(k_cum_E))

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

ev = [0] * n

for i in range(n):
    ev[i] = (1+p[i])/2

cs = [0] * n
cs[0] = ev[0]

for i in range(1,n):
    cs[i] = cs[i-1] + ev[i]

ans = cs[k-1]

for i in range(n-k):
    s = cs[i+k] - cs[i]
    if s > ans:
        ans = s

print(ans)

Solution (Python):
total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))

hope_array = [0.0] * total
for i in range(total):
   hope_array[i] = (dice_array[i] * (dice_array[i] + 1)) / 2 / dice_array[i]

dice_total = [0]
 
for i in range(total):
  dice_total.append(hope_array[i] + dice_total[i])
 
ans = dice_total[tar]
tar_num = tar
for i in range(total - tar):
  tmp = dice_total[i + 1 + tar] - dice_total[i + 1]
  if ans < tmp:
    ans = tmp

print(ans)

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

*e, = map(lambda x: (x*(x+1)//2)/x, p)

cusum = [0]*(n+1)
for i in range(n):
    cusum[i+1] = cusum[i]+e[i]

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

print(ans)

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

sum_K = [0]*(N-K+1)
sum_K[0] = sum(nums[:K])
for pos in range(1,N-K+1):
    sum_K[pos] = sum_K[pos-1] -   \
        nums[pos-1] + nums[pos+K-1]

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

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

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
S =[0] * (N - K + 1)
S[0] = sum(P[0:K])

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

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

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

INDEX = 0
total = 0
for i in range(K):
    total += P[i]

tmp = total
for i in range(N - K):
    tmp = tmp - P[i] + P[i + K]
    
    if tmp > total:
        total = tmp
        INDEX = i+1







    




ans = 0
for i in range(K):
    ans += P[i+INDEX] * (P[i+INDEX]+1) / (2*P[i+INDEX])

print("{:.12f}".format(ans))

Solution (Python):
import numpy as np

n,k = map(int,input().split())
lst = list(map(int,input().split()))
exp_val = [(l+1)/2 for l in lst]

cumsum = np.cumsum(exp_val)

for i in range(k-1, n):
    if i==k-1:
        val = cumsum[i]
    else:
        val = max(val, cumsum[i] - cumsum[i-k])
print(val)

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

max_mean = 0
for i in range(k):
    max_mean += 0.5 * (p[i] + 1)

cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(cur, max_mean)

print(max_mean)

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

max_mean = 0
for i in range(k):
    max_mean += 0.5 * (p[i] + 1)

cur = max_mean
for l in range(k, n):
    cur += 0.5 * (p[l] - p[l-k])
    max_mean = max(max_mean, cur)

print(max_mean)

Solution (Python):
from itertools import accumulate
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
P = [int(_) for _ in stdin.readline().rstrip().split()]
evs = [(1+p)/2 for p in P]
evs = [0] + list(accumulate(evs))
ans = 0
for i in range(K, N+1):
    ans = max(ans, evs[i]-evs[i-K])
print(ans)

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

n, k, *p = map(int, read().split())
tmp = sum(p[:k])
res = tmp
for i in range(k, n):
  tmp = tmp - p[i - k] + p[i]
  if tmp > res:
    res = tmp
print((res + k) / 2)

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

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

ans=0
for j in range(N-K+1):
  if j==0:
    tmp = sum(p[0:K])
  else:
    tmp = tmp - p[j-1] + p[j+K-1]
  
  if ans < tmp:
    ans = tmp

print(ans)

Solution (Python):
import numpy as np
N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]
accum_expect=[0]+list(np.cumsum(e_list))

n=N-K+1
expect_list=[accum_expect[i+K]-accum_expect[i] for i in range(0,n)]

print(max(expect_list))

Solution (Python):
from itertools import*
n,k,*p=map(int,open(0).read().split())
q=[0]+list(accumulate([(x+1)/2 for x in p]))
print(max(q[i+k]-q[i] for i in range(n-k+1)))

Solution (Python):
n, k = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
e = [(1 + p[i]) * 0.5 for i in range(n)]
s = 0.0
for i in e[:k]:
    s += i
t = s
for i in range(n - k):
    t = t - e[i] + e[k + i]
    s = max(s, t)
print(s)

Solution (Python):
n,k=map(int,input().split())
p=[int(x) for x in input().split()]

for i in range(n):
    p[i]+=1

sdict={}
sdict[0]=p[0]

for i in range(n-1):
	sdict[i+1]=sdict[i]+p[i+1]
j=0
ans=0
if n!=k:
	while (j+k <n):
		dif=sdict[j+k]-sdict[j]
		ans=max(dif,ans)
		j+=1
else:
	ans=sum(p)
print(ans/2)

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

cnt=0
for i in range(k):
    cnt+=p[i]
ans=cnt
for j in range(k,n):
    cnt=cnt-p[j-k]+p[j]
    ans=max(cnt,ans)


print('{:.20f}'.format((ans+k)/2))