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):
def run():
  N, K = map(int, input().split())
  ps = list(map(int, input().split()))
  dp = [0]*(N-K+1)
  ans = 0
  dp[0] = sum(ps[0:K])
  for n in range(1, N-K+1):
    dp[n] = dp[n-1]+ps[n+K-1]-ps[n-1]
  print((max(dp)+K)/2)

if __name__ == '__main__':
    run()

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
add = [None]*(n-k+1)
add[0] = sum(p[:k])

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

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

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


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

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

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2))
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()

Solution (Python):
n,k = map(int,input().split())
p = list(map(int,input().split()))
maxer = sum(p[:k])
cnt = maxer
st = 0
for i in range(n-k):
    cnt = cnt - p[i] + p[i+k]
    if cnt >= maxer:
        maxer = cnt
        st = i+1
ans = 0
for i in range(st,st+k):
    if p[i]%2 == 0:
        ans += (p[i]//2+0.5)
    else:
        ans += (p[i]//2 + 1)
print(ans)

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

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

L2 = [0] * (N + 1)
for i in range(N):
    L2[i+1] = L2[i] + L[i]

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

print(x)

Solution (Python):
N,K=map(int,input().split())
P=list(map(int,input().split()))
sums=[sum(j for j in range(i+1)) for i in range(1001)]
ans=0

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

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

Solution (Python):
n,k=map(int,input().split())
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0.0
for j in range(k):
  a+=float(i[j+place]+1)/2
print(a)

Solution (Python):
def check(A):
  s = 0
  print(A)
  for i in A:
    s += (1+i)/2
    print(s)
  return s



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

now = 0
s = 0
for i,j in enumerate(p):
  if i <= K-1:
    s += (j+1)/2
  else:
    s -= (p[i-K]+1)/2
    s += (j+1)/2
  if now < s:
    now = s
  

print(now)

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

sk = sum(p[:k])
st = p[0]
c = 0
mp = sk

for i in range(k, n):
    sk = sk - p[i-k] + p[i]
    if mp < sk:
        mp = sk

print((mp+k)/2)

Solution (Python):

def calc_expect(n):
    return (n+1) / 2


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

p_expect_list = list(map(calc_expect, p_list))

max_val = 0

res = [0] * len(p_expect_list)
res[0] = p_expect_list[0]
for i in range(len(res)-1):
    res[i+1] = res[i] + p_expect_list[i+1]

if (n == k):
    print(res[-1])
    exit()

for i in range(len(p_expect_list)-k):
    val = res[i+k]-res[i]
    if val > max_val:
        max_val = val

print(max_val)

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

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

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

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

result=0
result+=total
for i in range(1,N-K+1):
   total=total-(p[i-1]+1)/2+(p[i+K-1]+1)/2
   result=max(result,total)

print(result)

Solution (Python):
nk=input().split(" ")
N=int(nk[0])
K=int(nk[1])
p=input().split(" ")
p=[int(s)+1 for s in p]

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

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

Solution (Python):
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) 
A = [int(input()) for _ in range(N)] 
lst = [list(map(int,input().split())) for i in range(M)] 
"""

N, K = map(int,input().split())
P = list(map(int,input().split()))
Q = [(1.0+P[i])/2.0 for i in range(N)]

lst = []
Q.insert(0, 0)
P_cumsum = np.cumsum(Q)

for i in range(N-K+1):
  var = P_cumsum[K+i] - P_cumsum[i]
  lst.append(var)
  
ans = max(lst) * 1.0

print(ans)

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

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

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

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

lst = [0]*(N+1)
for i in range(1,N+1):
    lst[i] = lst[i-1] + 0.5*(p[i-1]+1)
ans = 0
for i in range(K,N+1):
    ans = max(ans,lst[i]-lst[i-K])

print(ans)

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

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


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

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

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

E[N-K] = sum(P[N-K:])
maxE = max(E)

print((maxE - K) / 2.0 + K)

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

import numpy as np

data = np.fromstring(read(), np.int64, sep=' ')

N, K  = data[:2]
P = np.hstack([[0], data[2:] + 1])

Pcum = P.cumsum()
x = Pcum[K:] - Pcum[0:-K]
print(x.max() / 2)

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    P = [int(x) for x in stdin.readline().rstrip().split()]
    E = [((p*(p+1))/2)/p  for p in P]
    maxe = sum(E[0:0+K])
    frontval = maxe
    for i in range(1, N-K+1):
        val = frontval - E[i-1] + E[i+K-1]
        frontval = val
        if maxe < val:
            maxe = val
    print(maxe)

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
want = sum(p[0:K])
change = sum(p[0:K])

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

print((K+want)/2)

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

s = sum(P[:K])
m = s
for i in range(N-K):
  s += P[i+K] - P[i]
  m = max(m, s)
print((m + K) / 2)

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

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

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

print(ans)

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

Solution (Python):
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
p_acc = list(accumulate(p))
ans_max = p_acc[k-1]
ans = 0
if n > k:
    for i in range(n-k):
        ans_max = max(ans_max, p_acc[i+k] - p_acc[i])
        if p_acc[i+k] - p_acc[i] == ans_max:
            ans = i
    print((p_acc[ans+k] - p_acc[ans] + k) / 2)
else:
    print((sum(p) + n) / 2)

Solution (Python):
n,m = map(int,input().split())
l = list(map(int,input().split()))

ans = 0
for i in range(m):
    ans += l[i]
a = ans
for i in range(m,n):
    a = a+l[i]-l[i-m]
    if a > ans:
        ans = a
print((ans+m)/2)

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

def f(p):
    
    return (p+1)/2


p2 = []

for p_tmp in p:
    p2.append(f(p_tmp))

p3 = [p2[0]]

for i in range(1,len(p2)):
    p3.append(p2[i]+p3[i-1])

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

print('{:.20f}'.format(ans))

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

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

Solution (Python):

import numpy as np
n, k = map(int, input().split())
p = list(map(int, input().strip().split()))
p = np.array(p)
def calc_E(p):
    return ((p+1)/2)

q = (p+1)/2


sum = np.cumsum(q)

sum2 = np.zeros((n+1))
sum2[1:] = sum
max = -1
for i in range(k,n+1):
    tmp = sum2[i] - sum2[i-k]
    if max < tmp:
        max = tmp

print(max)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *P = map(int, read().split())

P_ = [0] * N

acc = sum(P[:K])
ans = (acc + K) / 2

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

print(ans)

Solution (Python):
N, K = map(int,input().split())
P = list(map(float,input().split()))
for i in range(N):
    P[i] = (P[i]+1.0)/2.0

anss=0        
for i in range(N-K+1):
    
    
    if i==0:
        ans_kari = sum(P[i:i+K])
    else:
        ans_kari = ans_kari - P[i-1] + P[i+K-1]
    
    
    if ans_kari > anss:
        anss = ans_kari

print(anss)

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


max = 0
max_i = 0
for i in range(n - k + 1):
  total = A[i+k] - A[i]
  if max < total:
    max = total
    max_i = i

print((max + k) / 2)

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

result = []
num = 0

for i in range(K):
    num += List[i]

result.append(num)
    
for i in range(N-K):
    num = num - List[i] + List[K+i]
    result.append(num)

print(max(result) / 2 + 0.5*K)

Solution (Python):


def solve():
    N, K = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    kitai = []  
    for p in Ps:
        kitai.append(((1+p)*p/2)*(1/p))

    
    
    ans = 0
    for i in range(0, K):
        ans += kitai[i]

    
    total = ans
    for i in range(K, N):
        total = total + kitai[i] - kitai[i-K]
        if total > ans:
            ans = total

    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
def solve():
    N, K, *p = map(int, open(0).read().split())
    
    idx = 0
    tmp, p_sum = sum(p[:K]), sum(p[:K])
    for i in range(N - K):
        tmp -= p[i]
        tmp += p[i + K]
        if p_sum < tmp:
            p_sum = tmp
            idx = i + 1
    
    cumsum = [i for i in range(1, 200001)]
    for i in range(1, 200000):
        cumsum[i] += cumsum[i - 1]
    
    ans = 0
    for i in range(idx, idx + K):
        ans += cumsum[p[i] - 1] / p[i]
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

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

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

e = (p + 1) / 2

ans = 0
sum = 0

for i in range(n - k + 1):
    if i == 0:
       ans = np.add.reduce(e[:k])
       sum = np.add.reduce(e[:k])

    else:
        sum = sum - e[i-1] + e[i+k-1]
        if ans < sum:
            ans = sum + 1 - 1

print(ans)

Solution (Python):
from itertools import accumulate
n,k = map(int,input().split())
p = list(map(int, input().split()))
a = [0] + p
a = list(accumulate(a))
num = 0
summ = 0
for i in range(len(a)-k):
    if(a[i+k]-a[i]>summ):
        num = i
        summ = a[i+k]-a[i]
ans = 0
for i in range(k):
    ans += p[num+i]*(p[num+i]+1)/(2*p[num+i])
print(ans)

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

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

sum_p = sum(p_list[0:K])
ans = sum_p
for i in range(1, N-K+1):
  sum_p = sum_p - p_list[i-1] + p_list[i+K-1]
  if ans < sum_p:
    ans = sum_p

print(ans)

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

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

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












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

print(ans)

Solution (Python):


n, k = map(int, input().split())
p_list = list(map(int, input().split()))
score = []
for p in p_list:
    score.append((p + 1) / 2)

max_score = 0
flag = 0
total_score = 0
for i in range(n):
    if i < k - 1:
        total_score += score[i]
    else:
        total_score += score[i]
        max_score = max(max_score, total_score)
        total_score -= score[i - k + 1]
print(max_score)

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

Solution (Python):
n , k =list(map(int,input().split()))
p = list(map(int,input().split()))
maxval = sum(p[0:k])
now = sum(p[0:k]) + p[-1] - p[k-1]
for i in range(n-k+1):
    now = now - p[i-1] + p[i+k-1]
    if  now > maxval:
        maxval = now

print((maxval+k)/2)

Solution (Python):

N, K=(int(i) for i in input().split())
P=[int(i) for i in input().split()]

Q=[(P[i]+1)/2 for i in range(len(P))]
R=[0]*(len(Q)+1)
for i in range(1,len(R)):
    R[i] = R[i-1] + Q[i-1]
maxp=0
for i in range(N-K+1):
        maxp=max((R[i+K]-R[i]), maxp)
print(maxp)

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
max_l = 0
point = sum(p[:K])
index = 0

for i in range(1,N-K+1):
  point -= (p[i-1] - p[i+K-1])
  if point > max_l:
    max_l = point
    index = i
print(sum([(n+1)/2 for n in p[index:index+K]]))

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

num=sum(p[:k])
tot=[num]
t_append=tot.append
for i in range(n-k):
  tmp=p[i+k]-p[i]
  num+=tmp
  t_append(num)

print(max(tot)/2)

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

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
p_ex = []
for p_one in p:
    p_ex.append(p_one / 2 + 0.5)

sum_ex = 0

for i in range(k):
    sum_ex += p_ex[i]

sum_ex_prev = sum_ex
for i in range(n - k):
    sum_ex_tmp = sum_ex_prev
    sum_ex_tmp -= p_ex[i]
    sum_ex_tmp += p_ex[i + k]
    sum_ex = max(sum_ex, sum_ex_tmp)
    sum_ex_prev = sum_ex_tmp

print(sum_ex)

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

if n!=k:
    print((c+k)/2)
else:
    print((s[-1])/2+0.5*k)

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)

Solution (Python):
def main():
	import sys
	input = sys.stdin.readline
	N, K = list(map(int, input().split()))
	p = list(map(int, input().split()))
	ans = sum(p[:K])
	car = ans
	for i in range(N-K):
		car = car + p[i+K] - p[i]
		ans = max(ans, car)
	print((ans + K) / 2)

if __name__ == '__main__':
    main()

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

Solution (Python):


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

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

max_sum = sum(expect[:K])
new_sum = sum(expect[:K])
for i in range(0, N-K):
    new_sum += expect[i+K] - expect[i]
    if max_sum < new_sum:
        max_sum = new_sum

print(max_sum)

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

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

a=[0]*N

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

sums=[0]*(N+1)

sums[0]=0
for i in range(1,N+1):
    sums[i]=sums[i-1]+a[i-1]

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

print(mx)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

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

s_max = sum(P[:K])

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

print((s_max + K)  / 2)

Solution (Python):
N, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
def get_expectation(n):
  return n*(2+n-1)/2/n
A = [get_expectation(i) for i in A]
maximum = sum([A[i] for i in range(K)])
tmp = maximum
for i in range(N-K):
  diff = A[i+K]-A[i]
  if tmp+diff >= maximum:
    maximum = tmp+diff
  tmp = tmp+diff
print(maximum)

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
P = [int(x) for x in input().strip().split()]
q = deque([])
cur = 0
ans = 0
for i, p in enumerate(P):
    e = (1+p) / 2
    q.append(e)
    cur += e
    if i >= K-1:
        ans = max(ans, cur)
        e_ = q.popleft()
        cur -= e_
print(ans)

Solution (Python):
N, K = [int(x) for x in input().split()]
l = [(int(x)+1)/2 for x in input().split()]
t = sum(l[:K])
ans = t
for i in range(N-K):
  t = t - l[i] + l[K+i]
  ans = max(ans, t)
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
C = [ 0 for _ in range(N+1) ]
C[0] = 0
for i in range(1,N+1):
  C[i] = p[i-1] + C[i-1]
ans = 0
for i in range(0,N-K+1):
  ans = max( C[i+K]-C[i], ans )
print(ans)

Solution (Python):

N,K = map(int,input().split())
p = list(map(int,input().split()))
q = [0 for _ in range(N)]

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

S = sum(q[0:K])
Smax = S
for i in range(N-K):
    S = S - q[i] + q[K+i]
    if S > Smax:
        Smax = S

print(Smax)

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

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

ans_index = 0
total = sum(P[0:K])
prev = total
for i in range(N-K):
    tmp = prev + P[i+K] - P[i]
    if tmp > total:
        total = tmp
    prev = tmp

print((total + K) * 0.5)

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



expected_values = [num * (num + 1) / 2 / num for num in nums]

accums = [0]
for e in expected_values:
    accums.append(accums[-1] + e)

m = 0
for i in range(n-k+1):
    m = max(m, accums[i+k] - accums[i])
print(m)

Solution (Python):
n,k=[int(x) for x in input().split()]
p=[(int(x)+1)/2 for x in input().split()]
dp=[0]*(n-k+1)
dp[0]=sum(p[:k])
for i in range(1,n-k+1):
    dp[i]=dp[i-1]+p[k+i-1]-p[i-1]
print(max(dp))

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

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

    total = sum(A[0:K])
    total_max = total
    for i in range(0, N-K):
        total -= A[i]
        total += A[i+K]
        total_max = max(total, total_max)

    print((total_max+K)/2)

if __name__ == '__main__':
    resolve()

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

window = [sum(ps[:k])]
for i in range(n-k):
  n = window[i]
  m = n - ps[i] + ps[i+k]
  window.append(m)


print((max(window)-1)*0.5+1+0.5*(k-1))

Solution (Python):
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p_acc = tuple(accumulate(p))
    p_max = p_acc[k-1]
    if n == k:
        print((p_acc[-1]+k)/2)
        return
    for i in range(n-k):
        p_max = max(p_acc[i+k]-p_acc[i], p_max)
    print((p_max+k)/2)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=0
b=[]
for i in range(k):
  s+=a[i]
b.append(s)
for i in range(k,n):
  s+=a[i]
  s-=a[i-k]
  b.append(s)
m=max(b)
print(m/2+0.5*k)

Solution (Python):

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

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

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

Solution (Python):


iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    P = list(iim())
    P2 = list(map(lambda x: x * (x + 1) / x / 2, P))

    ip = enumerate(P2)
    val = ans = 0
    for i in range(K-1):
        j, p = next(ip)
        val += p

    for i, p in ip:
        val += p
        if val > ans:
            ans = val
        
        val -= P2[i-K+1]
    print(ans)

if __name__ == "__main__":
    resolve()

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

s = sum((1 / a[i]) * (a[i] * (a[i] + 1) // 2) for i in range(k))

m = s

for i in range(k, n):
    s += (1 / a[i]) * (a[i] * (a[i] + 1) // 2)

    i -= k

    s -= (1 / a[i]) * (a[i] * (a[i] + 1) // 2)

    m = max(m, s)

print('%.12f'%m)

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

Solution (Python):

import sys
import math
import numpy as np
import itertools


n,k = (int(i) for i in input().split())  

p = [int(i) for i in input().split()] 

q = [0]*(n-k+1)

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

for i in range(k,n):
    q[i-k+1] = q[i-k]+p[i]-p[i-k]
maxsum=0
for i in range(n-k+1):
    maxsum=max(maxsum,q[i])

print((maxsum+k)/2)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int, input().split())) 
ans0=sum(A[0:K])
ans=ans0
for i in range(0,N-K):
  ans=ans-A[i]+A[K+i]
  if ans>ans0:
    ans0=ans
    
ans=(ans0+K)*0.5
print(ans)

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

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

per = [ (n + 1) / 2 for  n in P]

m = [0] * N
m[0] = sum(per[ : K])
for x in range(1, N - K + 1):
    m[x] = m[x - 1] - per[x - 1] + per[x + K - 1]


print(max(m))

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

Solution (Python):
n,k = map(int, input().split())
p = list(map(int, input().split()))
m = sum(p[:k])
q = m
for i in range(n - k):
    q = q - p[i] + p[i + k]
    if q > m:
        m = q

print((k + m) / 2)

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
S = sum(P[:K])
M = S
for k in range(N - K):
    S = S - P[k] + P[k + K]
    if M < S:
        M = S
print((M + K)/2)

Solution (Python):

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

x = sum(l[:k])
max_val = x
for i in range(n-k):
    x = x-l[i]+l[i+k]
    if x > max_val:
        max_val = x

print((max_val+k)*1.0/2)

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

e=[0] 
def calc(num):
    re=0
    kaku=1/num
    for i in range(1,num+1):
        re+=kaku*i
    return re
for i in range(1,1001):
    e.append(calc(i))

for i in range(n):
    a=p[i]
    p[i]=e[a]
    

wa=[0,p[0]]
for i in range(1,n):
    wa.append(wa[i]+p[i])

ans=0
for i in range(1,n+1):
    s=i
    g=i+(k-1)
    if n<g:
        break
    now_=wa[g]-wa[s-1]
    if ans<now_:
        ans=now_
print(ans)

Solution (Python):
N,K = map(int,input().split())
P = [(int(i)+1)/2 for i in input().split()]
max_p = 0
for n in range(N-K+1):
    if n == 0:
        temp = sum(P[0:K])
    else:
        temp -= P[n-1]
        temp += P[n+K-1]
    max_p = max(max_p,temp)
print(max_p)

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

def excepted_value(p):
    return p * (p+1) // 2

def solve(N, K, P):
    s = [0 for i in range(N+1)]
    for i in range(1, N+1):
        s[i] = s[i-1] + P[i-1]
    max_left_value = -1
    max_left_idx = -1
    for i in range(N+1-K):
        if s[i+K] - s[i] > max_left_value:
            max_left_value = s[i+K] - s[i]
            max_left_idx = i
    excepted_value_sum = 0.0
    for i in range(max_left_idx, max_left_idx+K):
        excepted_value_sum += float(excepted_value(P[i])) / P[i] 
    return excepted_value_sum


if __name__ == '__main__':
    inputs = read()
    print("%.8f" % solve(*inputs))

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

    temp = 0
    for k in range(K):
        temp += calc_e(p[k])
    res = temp
    for n in range(N-K):
        temp -= calc_e(p[n])
        temp += calc_e(p[n+K])
        if(temp > res): res = temp
    print(res)


def calc_e(pi):
    return(sum(range(1,pi+1))/pi)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N,K = map(int,input().split())
p = np.array(list(map(int,input().split())))
e = (p+1) / 2.0
s = np.zeros(len(e)+1)
s[1:] = np.cumsum(e)
f = s[K:] - s[:-K]

print(np.max(f))

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

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

d=a[0]
for i in range(1,n-k+1):
    
    tmp=now-d+a[i+k-1]
    ans=max(ans,tmp)
    d=a[i]
    now=tmp
    
    
print(ans)

Solution (Python):
import itertools

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

e = []

ans = 0

l = 1
r = 1


def getExp(n):
    return (n*(n+1)/2) / n

for i in range(n):
    e.append(getExp(p[i]))

s = [0] + list(itertools.accumulate(e))

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




print(ans)

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

Solution (Python):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6)
input=stdin.readline

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
kitai=[0]
for i in range(1,1001):
    tmp=0
    d=1/i
    for j in range(1,i+1):
        tmp+=j*d
    kitai.append(tmp)

ac=[0]
for i in a:
    ac.append(ac[-1]+kitai[i])

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

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


def kitai(i: int) -> int:
    if i % 2:
        return ((1 + i) * (i // 2) + (i // 2) + 1) / i
    else:
        return ((1 + i) * (i // 2)) / i


kitai_dict = dict()
kitai_list = list()

for i in range(n):
    if a[i] in kitai_dict:
        kitai_list.append(kitai_dict[a[i]])
    else:
        kitai_dict[a[i]] = kitai(a[i])
        kitai_list.append(kitai_dict[a[i]])

current_sum = sum(kitai_list[:k])
ans = current_sum
for i in range(k, n):
    current_sum += kitai_list[i]
    current_sum -= kitai_list[i - k]
    ans = max(ans, current_sum)

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
cnt=sum(p[0:k])
ans=[]
ans.append(cnt)
for i in range(n-k):
    cnt=cnt-p[i]+p[i+k]
    ans.append(cnt)



print(max(ans))