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):
query=[int(x) for x in input().split()]
N = query[0]
K = query[1]
L = list()
L = [int(x) for x in input().split()]



def prob(x):
    out = 0.0

    out = (x+1)/2

    return out















res=0.0
tres=0.0
for i in range(0,K):
    tres+=prob(L[i])
    res=max(res,tres)
rindex=K
lindex=0
while rindex<N:
    tres=tres-prob(L[lindex])+prob(L[rindex])
    rindex+=1
    res=max(res,tres)
    lindex+=1
print("%14.12f"%res)

Solution (Python):
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
s=sum(l[:k])
ma=s
i=0
while i+k<len(l):
    s-=l[i]
    s+=l[i+k]
    ma=max(ma,s)
    i+=1
print((ma+k)/2)

Solution (Python):
pre_N_list=input()
N_list=pre_N_list.split(' ')
N=int(N_list[0])
K=int(N_list[1])
p=input()
p_list=p.split(' ')
exp=[]
com=[]
com_sum=[]
t=0
for i in range(N):
  p_list[i]=int(p_list[i])
for i in range(1000):
  exp.append((1+i+1)*(i+1)/(2*(i+1)))

for i in range(N):
  com.append(exp[p_list[i]-1])


for i in range(N):
  t+=com[i]
  com_sum.append(t)


com_dif=[]
com_dif.append(com_sum[K-1])
for i in range(N-K):
  com_dif.append(com_sum[i+K]-com_sum[i])

print(max(com_dif))

Solution (Python):
import sys
from itertools import accumulate

def main():
    
    

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    
    s = [0] + p
    s = list(accumulate(s))

    
    
    maxp = 0
    idx = 0
    for i in range(n - k + 1):
      nowp = s[i + k] - s[i]
      
      
      if maxp < nowp:
        maxp = nowp
        idx = i

    

    sump = 0
    for j in range(idx, idx+k):
      sump += p[j] * (p[j] + 1) / 2 / p[j]

    print(sump)
        
if __name__ == '__main__':
    main()

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

Solution (Python):
n,k = map(lambda x: int(x),input().split())
p = list(map(lambda x: (int(x) + 1)/2,input().split()))
ruiseki = [0]
max = 0
for i in range(n) :
    ruiseki.append(ruiseki[i]+p[i])

for j in range(n - k + 1):
    if max < (ruiseki[j+k] - ruiseki[j]) :
        max = (ruiseki[j+k] - ruiseki[j])


print(max)

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

total = sum(P[:k])
tmp = total
start = 0
for i in range(0, n - k):
    tmp = tmp - P[i] + P[i + k]
    if total < tmp:
        total = tmp
        start = i + 1

ret = 0
for i in range(start, start + k):
    ret += (P[i] + 1) / 2

print(ret)

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

S = 0
maxsum = 0
for i in range(K):
    S += (p[i]+1)/2

for i in range(K,N):
    if(maxsum < S):
        maxsum = S
    S = S + (p[i]+1)/2 - (p[i-K]+1)/2

if(maxsum < S):
    maxsum = S

print(maxsum)

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

s = [0] * (n-k+1)
for i in range(0, k):
    s[0] += p[i]

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

ans = 0
for i in range(max_i, max_i+k):
    ans += p[i] * (p[i]+1) / 2 / p[i]

print("%.8f" % ans)

Solution (Python):
import numpy as np

N,K = [int(i) for i in input().split()]
n = np.array([int(i) for i in input().split()])
n=(n+1)
t=np.empty(N+1)
t[0] = 0
t[1:]=np.cumsum(n)
print(max(t[K:]-t[:-K])*0.5)

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

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

print((ans + k) * 0.5)

Solution (Python):
N , K= map(int, input().split())
A =list(map(int, input().split()))
B=[0 for _ in range(N+1)]
for i in range(N):
    A[i] = (A[i]+1)/2
for i in range(N):
    B[i+1]=B[i]+A[i]

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

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]

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

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


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

mm = prefix[k-1]
idx = 0
for i in range(k,len(nums)):
    curr = prefix[i] - prefix[i-k]
    if curr > mm:
        mm = curr
        idx = i

s = 0
for i in range(idx-k+1,idx+1):
    s += (nums[i]+1)/2
print(s)

Solution (Python):
import numpy as np

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

p_mapped = [(i + 1) / 2 for i in p]
p_m_cumsum = np.cumsum(p_mapped)

max = 0
for i in range(len(p_m_cumsum)-K+1):
    if i != 0:
        answer = p_m_cumsum[i+K-1] - p_m_cumsum[i-1]
    else:
        answer = p_m_cumsum[i+K-1]
    if answer >= max:
        max = answer
print(max)

Solution (Python):
import numpy as np

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

e = (p + 1) / 2



cum_e = np.zeros(N + 1)
cum_e[1:] = np.cumsum(e)



s = cum_e[K:] - cum_e[:-K]

print(max(s))

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

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

n = 0
for i in range(N):
    n += l[i]
    l[i] = n

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

print(ans)

Solution (Python):

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


import numpy as np
p = np.array(p)
q = np.cumsum(p)

answer = (K + q[K-1])/2
for i in range(K, N):
    answer = max(answer, (K + q[i] - q[i-K])/2)

print(answer)

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

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

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

S = []
for i in range(len(P)):
    if(i > 0):
        S.append(P[i]+S[i-1])
    else:
        S.append(P[0])


max = S[K-1]
for i in range(len(S)-K):
    a = S[i+K]-S[i]
    

    if(a > max):
        max = a












print("{0:6f}".format(max))

Solution (Python):
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0] + list(accumulate(P))
print((max(b - a for a, b in zip(acc, acc[K:])) + K) / 2)

Solution (Python):
n,k = tuple(map(int,input().split())) 
N = list(map(int,input().split()))
s = sum(N[0:k])
m = sum(N[0:k])

for i in range(0,n-k):
    s = s-N[i]+N[i+k]
    m = max(m,s)   
print((m+k)/2)

Solution (Python):
N,K=map(int,input().split())
tu=tuple(map(int,input().split()))
l=[0]*(N+1)
l[0]=0
ans=0
for i in range(1,N+1):
  l[i]=l[i-1]+(tu[i-1]+1)/2
  if i>=K:
    ans=max(ans,l[i]-l[i-K])
print(ans)

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

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

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

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

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

sum = 0
for i in range(K):
    sum += p[i]
Max = sum
for i in range(K, N):
    sum += p[i] - p[i - K]
    Max = max(sum, Max)

print((Max + K) / 2)

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

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

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

Solution (Python):
import numpy

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

K = A[1]
N = A[0]

P = list(map(float, input().split()))

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

cumEP = list(numpy.cumsum(EP))

new_list = []

if N>K:
    for val in range(N-K):
        new_list.append(cumEP[val+K]-cumEP[val])
    print(max(new_list))
else:
    print(sum(EP))

Solution (Python):
import numpy as np
N, K = map(int, input().split())
P = (np.array(input().split(), dtype=np.int64) + 1) / 2

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

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

for i in P:
  Q.append((i+1)/2)

for i in range(N):
  R.append(R[i] + Q[i])

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

print(result)

Solution (Python):
from itertools import accumulate

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

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]+list(accumulate(x))

mm=0
inx=-1
for i in range(len(b)-k):
 if b[i+k]-b[i]>=mm:
  inx=i
  mm=b[i+k]-b[i]


ans=0
for j in range(inx,inx+k):
  ans+=((p[j]*(p[j]+1))*0.5)*(1/p[j])

print(ans)

Solution (Python):
from itertools import accumulate

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

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]+list(accumulate(x))

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

print(ans)

Solution (Python):
from itertools import accumulate

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

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]+list(accumulate(x))

'''
bb=[0]
for i in range(1,n+1):
 bb.append(bb[i-1]+x[i-1])

print(b)
print(bb)
'''

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

print(ans)

Solution (Python):
n, k = map(int, input().split())
p_cumsum = [0]
for p in map(int, input().split()):
  p_cumsum += [p_cumsum[-1]+p]
pk_max = 0
for i in range(k, n+1):
  pk_max = max(pk_max, p_cumsum[i]-p_cumsum[i-k])
print((pk_max+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):
    q0 = Q[i - K]
    q1 = Q[i]
    s += (q1 - q0)
    ans = max(ans, s)
print(ans)

Solution (Python):
import sys

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
P = [i for i in P if 1 <= i and i <= 10**3]
Q = [] 
S = [] 
T = [] 
s=0

if not 1 <= K <= N <= 2*10**5:
    sys.exit()

for i in range(N):
    
    q = (1 + P[i]) / 2
    Q.append(q)
    s += q
    S.append(s)
    if i == K-1:
        T.append(S[i])
    if i > K-1:
        T.append(S[i]-S[i-K])
print(max(T))

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

Solution (Python):
from itertools import accumulate

def main():
    N, K= map(int, input().split())
    p = list(map(int, input().split()))
    
    p = [0] + list(accumulate(p))

    
    print((max(b - a for a, b in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
  	main()

'''
5 3
1 2 2 4 5

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

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


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum


print(mmax)

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

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

p_sum = [0] * (n + 1)

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

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

ans = (ans + k) / 2
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
import numpy as np

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

n, k = na()
p = np.array(na())
p = (1+p)/2
now = sum(p[:(k)])
ans = now
for i in range(0, n-k):
    now = now - p[i] + p[i+k]
    ans = max(now, ans)
print("{:.8f}".format(ans))

Solution (Python):
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
if (n != k):
    pp = list(accumulate(p))
    ppp = [pp[i + k] - pp[i] + k for i in range(len(p) - k)]
    print((max(ppp)) / 2)
else:
    print((sum(p) + n) / 2)

Solution (Python):
Input1 = [int(_) for _ in input().split(" ")]
Input2 = [(int(i)+1)/2 for i in input().split(" ")]

sum_ = sum(Input2[:Input1[1]])
Max = sum_
for j in range(Input1[0]-Input1[1]):
    sum_ = sum_-Input2[j]+Input2[j+Input1[1]]
    if Max  < sum_:
        Max = sum_
        
print(Max)

Solution (Python):
def main():
  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(cur, ans)
  print(ans)
    

if __name__ == '__main__':
  main()

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

x=[]
for i in p:
 x.append((i+1)/2)

b=[0]
for i in range(1,n+1):
 b.append(b[i-1]+x[i-1])

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

print(ans)

Solution (Python):
import numpy

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

PP = [(1 + pp) / 2 for pp in P]

S = numpy.cumsum(PP).tolist()

r = -1
for i, ss in enumerate(S[K-1:]):
    r = ss if i == 0 else max(r, ss - S[i - 1])

print(r)

Solution (Python):
N, K = map(int, input().split())
acc = [0.0]
for x in map(int, input().split()):
    acc.append((1 + x) / 2)
    acc[-1] += acc[-2]
ans = 0.0
for start in range(N - K + 1):
    ans = max(ans, acc[start + K] - acc[start])
print(ans)

Solution (Python):


import numpy as np

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

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

exps = np.array(exps)
cumexps = exps.cumsum()
cumexps = np.insert(cumexps, 0, 0)




ans = -1
for i in range(n-k+1):
    tmp = -cumexps[i] + cumexps[i+k]
    if ans <= tmp:
        ans = tmp 

print(ans)

Solution (Python):

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

Solution (Python):
def kitaiti(number):
 return (1 + number)/2
def ruisekiwa(mylist):
    s = [0]
    t = 0
    for i in range(len(mylist)):
        t += mylist[i]
        s.append(t)
    return s
def wa(mylist,K):
    a = []
    i = 0
    while K + i < len(mylist):
        a.append(mylist[K + i]-mylist[i])
        i += 1
    return max(a)
N,K = (int(i) for i in input().split())
kitaiti = [kitaiti(int(x)) for x in input().split()]
print(wa(ruisekiwa(kitaiti),K))

Solution (Python):
n ,k = map(int ,input().split())
hai = list(map(lambda x:(int(x)+1)/2 ,input().split()))
hait= hai[:k]
ans = tmp = sum(hait)
for i in range(k,n):
  tmp = tmp - hai[i-k] + hai[i]
  if ans < tmp:
    ans = tmp
print(ans)

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


P = []
for p in _P:
  if p == 1:
    P.append(1)
  elif p%2 == 0:
    P.append(p//2+0.5)
  else:
    P.append(p//2+1)


ans = sum(P[:K])
_ = ans
for x in range(1,N-K+1,1):
  
  _ -= P[x-1]
  _ += P[x+K-1]
  
  
  ans = max(ans, _)
      
      
print(ans)

Solution (Python):
N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e

sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)

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

tmp = 0
m = 0
index = 0
for i in range(n - k + 1):
    if m < R[i + k - 1] - tmp:
        m = R[i + k - 1] - tmp
        index = i
    tmp = R[i]
ans = 0

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

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


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

ans = -1
ans = cand =  sum(nums[:K])
for i in range(K,len(nums)):
    cand = cand - nums[i - K] +  nums[i]
    ans = max(cand,ans)

print(ans)

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

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)

Solution (Python):
n, k = map(int, input().split(' '))
p = list(map(int, input().split(' ')))
m = []
t = sum(p[:k])
idx = 0
m.append(t)
for i in range(1, n - k + 1):
    t -= p[i - 1]
    t += p[i + k - 1]
    m.append(t)
mi = m.index(max(m))
pp = p[mi: mi + k]
pp.sort()
sg = 0
tp = 1
r = 0
for i in pp:
    for j in range(tp, i + 1):
        sg += j
    tp = i + 1
    r += sg / i
print(r)

Solution (Python):
n, k = map(int, input().split())
p = [(int(i)+1.0)/2.0 for i in input().split()]
ans = tmp = sum(p[:k])
for i in range(k,n):
    tmp += p[i]-p[i-k]
    ans = max(ans, tmp)
print('{:.12f}'.format(ans))

Solution (Python):

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

Solution (Python):

import sys
from itertools import accumulate

def solve(N: int, K: int, p: "List[int]"):
    accum_p = [0] + list(accumulate(p))
    max_index = 0
    max_value = 0

    for i in range(N-K+1):
        cur = accum_p[i+K]-accum_p[i]

        if cur > max_value:
            max_index = i
            max_value = cur
    

    ep = []
    for i in range(max_index,max_index+K):
        ep.append((1+p[i])/2)
    print(sum(ep))
    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())
p = [0]*k + list(map(int,input().split()))
ans = sum = 0
for i in range(n):
    sum += p[i+k] - p[i]
    ans = max(ans, sum)
print((ans+k)/2)

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

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
    for i, v in enumerate(a):
        ls[i] += (((1 + v) * v) // 2) / v
    ls = [0] + list(itertools.accumulate(ls))
    mt = 0
    for i in range(k, n + 1):
        mt = max(mt, ls[i] - ls[i-k])
    print(mt)


if __name__ == '__main__':
    solve()

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

Solution (Python):
import sys, math
import numpy as np
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
N, K = map(int, input().split())
pss = list(map(int, input().split()))
ps = [(p+1)/2 for p in pss]

acc = [0] * N
acc[0] = sum(ps[:K])
for i in range(1, N-K+1):
    acc[i] = acc[i-1] - ps[i-1] + ps[i+K-1]

mi = np.argmax(acc)

print(sum(ps[mi:mi+K]))

Solution (Python):



from itertools import accumulate

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

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

q = [] 
r = [] 
for i in range(n-k+1):
    q.append(p[i+k] - p[i])
    r.append((q[i] + k) / 2)

print(max(r))

Solution (Python):



from itertools import accumulate

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

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

q = [] 
r = [] 
for i in range(n-k+1):
    q.append(p[i+k] - p[i])
    r.append((q[i] + k) / 2)

print(max(r))

Solution (Python):
N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e

sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)

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

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

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

print((m+K)/2)

Solution (Python):
from itertools import accumulate

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


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



q = []
for i in range(n-k+1):
    q.append((p[i+k] - p[i] + k)/2)

print(max(q))

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

sum_array = [0] * (N + 1)
for i in range(1, N+1):
    exp = (1 + P[i-1]) / 2
    sum_array[i] = sum_array[i-1] + exp

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

print(expectation)

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

expect = []
for i in range(N):
  expect.append((1 + num[i]) / 2)
 

cs = [0]
for i in range(N):
    cs.append(cs[i]+expect[i])

max = 0
for i in range(K, N+1): 
  if max < cs[i] - cs[i-K]:
    max = cs[i] - cs[i - K]
print(max)

Solution (Python):
N,K= map(int,(input().split()))
p = list(map(int,input().split()))
rui_p=[]
rui_p.append(0)
sum_p=[]
for i in range(N):
  rui_p.append(rui_p[i]+p[i])
for j in range(K,N+1):
  sum_p.append(rui_p[j]-rui_p[j-K])

msp=max(sum_p)
ans=(msp/2)+(0.5*K)
print(ans)

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

value = [0]*N
k_list = []

for i in range(N):
    value[i] = (p[i]+1)*0.5
    
value_list = [0]*N

for i in range(N):
    value_list[i] = value_list[i-1] + value[i]

value_list.append(0)

for i in range(N-K+1):
    k_list.append(value_list[i+K-1]-value_list[i+K-(K+1)])
    
print(max(k_list))

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


expect = []
for i in range(N):
  expect.append((1 + num[i]) / 2)


cs = [0]
for (i, number) in enumerate(expect):
  cs.append(cs[i] + expect[i])

max = 0
for i in range(K, N+1): 
  if max < cs[i] - cs[i-K]:
    max = cs[i] - cs[i - K]
print(max)

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

Solution (Python):
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq


def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

def main():
    N, K = rip()
    A = ria()

    sum = [0] * (N + 1)
    for i in range(N):
        sum[i + 1] = sum[i] + A[i]
    
    ma = 0
    for i in range(N - K + 1):
        ma = max(ma, sum[i + K] - sum[i])
    print((ma + K) / 2.0) 



if __name__ == "__main__":
    main()

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(K,N+1):
    temp=S[i]-S[i-K]
    ans=max(ans,temp)
    
print((ans+K)/2)

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

tmp = 0
for i in range(K):
    tmp += P[i]
ans = tmp

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

print (ans)

Solution (Python):
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    P = tuple(map(int, input().split()))

    sum_ls = tuple(accumulate(range(max(P) + 1)))
    acc_P = [0] + list(accumulate([sum_ls[p] / p for p in P]))

    ans = 0
    for i in range(N - K + 1):
        v = acc_P[i+K] - acc_P[i]
        if v > ans:
            ans = v
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate

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

Solution (Python):
import numpy as np

N, K = map(int, input().split())
P_exp = np.array([0] + [(1+i)/2 for i in map(int, input().split())])
E_sum = np.cumsum(P_exp)

print((E_sum[K:]-E_sum[:-K]).max())

Solution (Python):
import numpy as np
n, k = list(map(int, input().split()))
p = np.array([0] + list(map(int, input().split())))
c = np.cumsum(p)
print((c[k:] - c[:-k] + k).max() / 2)

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

cur = sum(map(lambda x: (x + 1) * 0.5, p[:k]))
max_value = cur
l, r = 1, k
while r < n:
    cur += (p[r] - p[l-1]) * 0.5
    max_value = max(max_value, cur)
    l += 1
    r += 1
print(max_value)

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

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])
s[0] = s_0
for i in range(n-k):
    s[i+1] = s[i] + p[k+i] - p[i]

print((k+max(s))/2)

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

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

l, r = 1, k
cur = max_value
while r < n:
    cur += (p[r] - p[l-1]) * 0.5
    max_value = max(max_value, cur)
    l += 1
    r += 1
print(max_value)

Solution (Python):

def main(n,k,p):
    maxVal = 0
    
    kitai = [0] * n
    ruiseki = [0] * n
    kitai[0] = (p[0] + 1) / 2
    ruiseki[0] = (p[0] + 1) / 2
    
    for i in range(1, n):
        kitai[i] = (p[i] + 1) / 2
        ruiseki[i] = ruiseki[i-1] + kitai[i]
    
    for i in range(k-1, n):
        val = ruiseki[i] - (ruiseki[i-k] if i-k >= 0 else 0)
        maxVal = max(maxVal, val)
    return maxVal

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

Solution (Python):

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

sp = [0 for _ in range(n-k+1)]
sp[0] = sum(p[:k])
mv = sp[0]
mi = 0
for i in range(1, n-k+1):
    sp[i] = sp[i-1]
    sp[i] -= p[i-1]
    sp[i] += p[i+k-1]
    if mv < sp[i]:
        mv = sp[i]
        mi = i

exp = 0
for i in range(mi, mi+k):
    exp += (p[i] + 1) / 2.0

print(exp)

Solution (Python):
def main2(n,k,p):
    maxVal = 0
    
    kitai = [0] * n
    for i in range(n):
        kitai[i] = (p[i] + 1) / 2
    
    val = sum(kitai[:k])
    
    if k == n:
        return val
    for i in range(k,n):
        
        val = val + kitai[i] - kitai[i-k]
        maxVal = max(maxVal, val)
    return maxVal

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

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

ans = sum(P[0:K])
tmp = sum(P[0:K])

for i in range(1, N-K+1):
    tmp = tmp - P[i-1] + P[i+K-1]
    ans = max(tmp, ans)
print((ans + K)/2)

Solution (Python):
n, k = input().split()
N = int(n)
K = int(k)
p = input().split()
P = list(map(int, p))
 
tmp = 0
num = 0
hoge = 0
ans = []
for i in range(N):
    tmp += (P[i] * (P[i] + 1) / 2 / P[i])
    ans.append(tmp)
    tmp -= tmp
    if i == (K-1):
        num = sum(ans[0:K])
        hoge = num
    elif i > (K-1):
        num = num - ans[i-K] + ans[i]
        if num > hoge:
            hoge = num
print(hoge)

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

S_i = [0]
for i in range(n):
    S_i.append(S_i[i] + p_list[i])    


result_max = 0
for j in range(k, n+1):
    cad_max = S_i[j] - S_i[j-k]
    result_max = max(cad_max, result_max)

print(result_max)