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 = list(map(int, input().split()))

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

ans = [0]*(n)
tem = 0
for i in range(n):
    tem = tem
    if i < k:
        tem = tem + p[i]
    else:
        tem = tem + p[i] - p[i-k]
    ans[i] = tem

print(max(ans))

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

q = [0]
for v in p:
    q.append(q[-1] + v)

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

print(res)

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

expected = []
for val in p_l:
    expected.append((val+1)/2)

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

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

print(ans)

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

pref_sum = [None]* (N+1)
pref_sum[0] = 0
pref_sum[1] = (l[0]+ 1) / 2

for i in range(1, N):
    t = (l[i]+ 1) / 2
    pref_sum[i+1] = t + pref_sum[i]

ans = -float("inf")

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


print(ans)

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

pref_sum = [None]* (N+1)
pref_sum[0] = 0
pref_sum[1] = (1/l[0]) * ((l[0] * (l[0]+ 1)) / 2)

for i in range(1, N):
    t = (1/l[i]) * ((l[i] * (l[i]+ 1)) / 2)
    pref_sum[i+1] = t + pref_sum[i]

ans = -float("inf")

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


print(ans)

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

S = sum(p[:K])
S_MAX = S

for i in range(N-K):
    S += p[K+i] - p[i]
    if S_MAX < S:
        S_MAX = S

E = (S_MAX + K)/2

print(E)

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):
from itertools import accumulate
n, k = map(int, input().split())
P= list(map(int, input().split()))
e = [(1+p) / 2 for p in P]
ps =[0] + list(accumulate(e))
a = 0
for i in range(n+1- k):
    if a < ps[i+k] - ps[i]:
        a = ps[i+k] - ps[i]

print(a)

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

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

print('{:.10f}'.format(ans/2))

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

Solution (Python):

import sys

memory = {}

def expectation(x):
    if x in memory:
        return memory[x]
    else:
        return x * (1 + x) / (2 * x)

def solve(N: int, K: int, P: "List[int]"):
    largest = 0
    if K == 1:
        largest = expectation(max(P))
        print(largest)
        return

    for i, p in enumerate(P[:-K+1]):
        if i == 0:
            summation = 0
            for k in range(K):
                summation += expectation(P[i + k])
            if summation > largest:
                largest = summation
        else:
            summation -= expectation(P[i-1])
            summation += expectation(P[i + K - 1])
            if summation > largest:
                largest = summation

    print(largest)
    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 = 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):
N, K = map(int, input().split())
P = list(map(int, input().split()))
max_p = max(P)
dp = [0] * (max_p + 1)
dp[1] = 1
for i in range(2, max_p + 1):
    dp[i] = dp[i - 1] + 0.5
S = 0
for j in range(K):
    S += dp[P[j]]
ans = S
for i in range(1, N - K + 1):
    S = S - dp[P[i - 1]] + dp[P[i + K - 1]]
    ans = max(ans, S)
print(ans)

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

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

import numpy as np
cums=np.cumsum([0] + [exp(i) for i in p])

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

print(ans)

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

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

total=sum([exp(i) for i in p[:k]])
ans=total
bk=ans
for i in range(1, n-k+1):
    start=i-1
    end=start+k
    total=bk-exp(p[start])+exp(p[end])
    ans=max(ans, total)
    bk=total
    
print(ans)

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

    s = [0]
    for i in range(n):
        s.append(s[i]+e[i])

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


if __name__ == "__main__":
    main()

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

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


s = sum(e[:k])
ans = [s]
for i in range(n-k):
    s = s-e[i] + e[i+k]
    ans.append(s)


print(max(ans))

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

from itertools import accumulate
E = [(1+p)/2 for p in P]
ES = list(accumulate(E))

e = ES[K-1]
for i in range(N-K):
    e = max(e, ES[K+i] - ES[i])
print(e)

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]+1)/2)
ans = 0
for i in range(N-K+1):
    tmp = S[i+K] - S[i]
    ans = max(ans, tmp)
print('{:.20f}'.format(ans))

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

E = [(1 + p) / 2 for p in p]
curr_sum = sum(E[:K])
curr_max = curr_sum

for i in range(N - K):
    curr_sum += (E[i + K] - E[i])
    curr_max = max(curr_max, curr_sum)

print(curr_max)

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

sum_ans = sum([(i+1)/2 for i in P[0:K]])
result = [sum_ans]
for i in range(K,N):
    result.append(result[-1] + (P[i]+1)/2 - (P[i-K]+1)/2)

print(max(result))

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

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    Ep = [(x+1)/2 for x in p]


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

if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
result = 0
B = [a / 2 + 0.5 for a in P]

result = sum(B[0:K])
t = sum(B[0:K])
for i in range(N-K):
    t -= B[i]
    t += B[i+K]
    if t > result:
        result = t

print(result)

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

if __name__=="__main__":
    main()

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

for i in range(len(A)-K+1):
    if i == 0:
        t = sum(A[i:i+K])
    else:
        t -= A[i-1]
        t+= A[i+K-1]
    ans = max(ans,t)

print((ans+K)/2)

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


S = [0]*(n+1)
for i in range(1, n+1):
    S[i] = S[i-1]+P[i-1]

ans = max([S[x]-S[x-k] for x in range(k,n+1)])
print(ans)

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

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

l = list(map(int, input().split()))
l = [(i+1)/2 for i in l]

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

if n == 1:
    print(l[0])
else:
    lans = [ls[i+k]-ls[i] for i in range(len(ls)-k)]
    print(max(lans))

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

lis = list()

p = [(i + 1)/2 for i in p ]
numpy.set_printoptions(precision=16)

cumSum = numpy.cumsum(p)

cumSum2 = list(cumSum)

cumSum2.insert(0,0)

for i in range(0, N-K+1):
    lis.append(cumSum2[K+i] - cumSum2[i])

print('{:.12f}'.format(max(lis)))

Solution (Python):
import sys
import numpy as np

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, K = map(int, input().split())
    p = np.array(list(map(int, input().split())), dtype='f8')
    p = (p + 1) / 2
    rs = np.zeros(N + 1, dtype='f8')
    for i in range(N):
        rs[i + 1] = rs[i] + p[i]
    ans = 0
    for i in range(N - K + 1):
        ans = max(ans, rs[i + K] - rs[i])

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)

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

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

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

Solution (Python):
import itertools
N,K=map(int,input().split())
B=list(map(int,input().split()))
C=[0]+list(itertools.accumulate([(x+1)/2 for x in B]))

D=max(C[i]-C[i-K] for i in range(K,N+1))
print(D)

Solution (Python):
import itertools

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

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



ruiseki = [0] * (n+1)

for i, x in enumerate(ary):
    ruiseki[i+1] = ruiseki[i] + x

kmax = 0
for i in range(n+1-k):
    ksum = ruiseki[i+k] - ruiseki[i]
    kmax = max(kmax, ksum)

print((kmax+k) / 2)

Solution (Python):
from collections import deque

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

p_l = list(map(int, input().split())) 
p_sum_k_l = []

q = deque([])
first_sum = 0
for i in range(k):
    ex = (p_l[i]+1)/2
    q.append(ex)
    first_sum += ex

p_sum_k_l.append(first_sum)


for i in range(k, len(p_l)):
    
    poped = q.popleft()
    added = (p_l[i]+1)/2
    
    diff = added-poped
    
    next_sum = p_sum_k_l[-1] + diff
    p_sum_k_l.append(next_sum)
    q.append(added)

print(max(p_sum_k_l))

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

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

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

print(ans)

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

for i in range(N+1-K):
    T.append(S[i+K]-S[i])

print(max(T))

Solution (Python):
from collections import deque
n,k = map(int,input().split())
p = list(map(int,input().split()))
s = deque()
s.append(0)
tot = 0
for i in p:
    tot += i
    s.append(tot)

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

print((top+k)/2)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
a = list(map(lambda p_i: (p_i+1)/2, p))
ans = sum(a[:K])
m = sum(a[:K])

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

print(m)

Solution (Python):
import itertools
N, K = map(int, input().split())
p = list(map(int, input().split()))
ac = [0]+list(itertools.accumulate([(x+1)/2 for x in p]))

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

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

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

print(ans)

Solution (Python):
import itertools as iter

def main():
    n, k = list(map(int, input().split()))
    p = [0]
    p.extend(list(iter.accumulate([(1+int(x))/2 for x in input().split()])))
    
    
    s = []
    for i in range(n-k+1):
        s.append(p[i+k]-p[i])
    
    print(max(s))
    
if __name__ == '__main__':
    main()

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

expected = []
for i in range(N):
    expected.append((p[i]+1)/2)
m = [0] + list(accumulate(expected))
ans = 0
for i in range(1, len(m)-K+1):
    ans = max(ans, m[i+K-1] - m[i-1])
print(ans)

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

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

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

for j in range(N-K):
    if total>=now-(P[j]+1)/2+(P[j+K]+1)/2:
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
    else:
        total=now-(P[j]+1)/2+(P[j+K]+1)/2
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
print("{:.8f}".format(total))

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]

def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]

def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N,K = MI()
P = LI()
temp = 0
for i,v in enumerate(P):
    if i < K-1:
        temp += v
    elif i== K-1:
        temp += v
        ans = temp
    else:
        temp -= P[i-K]
        temp += v
        ans = max(ans,temp)
ans = (ans+K)/2
print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n, k = map(int, input().split())
    from itertools import accumulate
    A = list(map(int, input().split()))
    B = [0] + A
    B = list(accumulate(B))  
    num=0
    val=0
    
    for i in range(k, n + 1):
        if B[i]-B[i-k]>val:
            val=B[i]-B[i-k]
            num=i

    ans = 0
    for j in A[num-k:num]:
        ans += (0.5 * j * (1 + j)) / j
    print(ans)
resolve()

Solution (Python):

def main():
    import sys
    N, K =map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    
    
    P = list(map(lambda x:((x*(x+1)//2)/x), P))
    
    
    for i in range(N-1):
        P[i+1] +=P[i]
    
    ans = P[K-1]
    for i in range(N-K):
        ans = max(ans, P[K+i]-P[i])
    print(ans)
    
if __name__=='__main__':
    main()

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

def E(x):
    return (x*(x+1)//2)/x
def main():
    N, K = map(int, readline().split())
    e = [E(int(i)) for i in readline().split()]
    s = [0.]
    for i in range(N):
        s.append(s[i]+e[i])
    ans = 0.
    for i in range(N-K+1):
        ans = max(s[K+i]-s[i], ans)
    print('{:.12f}'.format(ans))
if __name__ == '__main__':
    main()

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

Solution (Python):
N, K = map(int, input().split())
ps = list(map(int, input().split()))
es = [(p+1)/2 for p in ps]
rs = []
s = sum(es[0:K])
rs.append(s)
for i in range(N-K):
  s = s-es[i]+es[i+K]
  rs.append(s)

r = max(rs)
print(r)

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

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

t = sum(Es[0:k])
ans = t

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

print(ans)

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

part=e[0:k]
kari=sum(part)
ans=kari
for i in range(n-k):
  kari+=e[i+k]
  kari-=e[i]
  if kari>ans:
    ans=kari
print(ans)

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 = list(map(int, input().split()))
ExP = list(map(lambda x: (x+1)/2, P))
ans = 0
prev = 0


now = sum(ExP[0: k])

ans = max(ans, now)
prev = now

for i in range(1, n-k+1):
    now = prev - ExP[i-1] + ExP[i+k-1]

    ans = max(ans, now)
    prev = now
print(ans)

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


exp = [0 for i in range(n+1)]

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

ans = 0
for i in range(k, n+1):
    ans = max(ans, exp[i] - exp[i-k])
print("{:.12f}".format(ans))

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

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

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

ans = 0
for i in range(k, n+1):
  ans = max(ans, l[i] - l[i-k])
print("{:.12f}".format(ans))

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

sum_p =[0]
tmp = 0
for i in p:
    tmp += i
    sum_p.append(tmp)

max_expect = 0
for i in range(k, n+1):
    tmp = sum_p[i] - sum_p[i - k]
    max_expect = max(tmp, max_expect)

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

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

awk = 0
aix = k - 1
for i in range(k):
  awk += a[i]
a_max = awk

for i in range(k,n):
  awk = awk + a[i] - a[i-k]
  if a_max < awk:
    a_max =  awk
    aix   = i

ans = 0.0

for i in range(aix-k+1,aix+1 ):
  
  ans += ( 1 + a[i] )  / 2.0

print(ans)

Solution (Python):
import numpy as np
from decimal import Decimal

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

if N==1:
    print((p.max() + 1) / Decimal(2))
elif N==K:
    print((p.sum() + K) / Decimal(2))
else:
    p = np.cumsum(p)

    ans = []
    for i in range(N - K):
        ans.append(p[i + K]-p[i])

    ans = (max(ans) + K) / Decimal(2)

    print(ans)

Solution (Python):

n, k = map(int, input().split())
p_list = list(map(int, input().split()))
e_list = [(1 + p) / 2 for p in p_list]
max_v = sum(e_list[:k])
ret = max_v

for i in range(n - k):
  calc = ret - e_list[i] + e_list[i + k]
  max_v = max(max_v, calc)
  ret = calc
  
print(max_v)

Solution (Python):
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ll = [l[k - 1]] + [j - i for i, j in zip(l, l[k:])]
    ans = max(ll)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ll = [l[k - 1]] + [l[i + k] - l[i] for i in range(n-k)]
    ans = max(ll)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ans = l[k - 1]
    for i in range(0, n - k):
        x = l[i + k] - l[i]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from copy import deepcopy

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

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


max_sum = 0
temp_sum = 0


for j in range(k):
    temp_sum += ((p[j] + 1) * p[j] / 2) / p[j]

if n == k:
    max_sum = temp_sum
    print(max_sum)

else:
    
    for i in range(1,n-k+1):
        temp_sum = temp_sum - ((p[i-1] + 1) * p[i-1] / 2) / p[i-1] + ((p[i+k-1] + 1) * p[i+k-1] / 2) / p[i+k-1]

        if temp_sum > max_sum:
            max_sum = temp_sum


    print(max_sum)

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
s = [0]
for i in range(n):
  if i==0:
    s.append(p[0])
  else:
    s.append(s[-1]+p[i])
pmax = 0
for i in range(n-k+1):
  if s[i+k]-s[i]>pmax:
    pmax = s[i+k]-s[i]
print(pmax)

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

def main():
  n,k=map(int,input().split())
  p=list(map(lambda x:(1+int(x))/2,input().split()))
  sumk=sum(p[:k])
  ans=sumk
  for i in range(n-k):
    sumk-=p[i]
    sumk+=p[i+k]
    ans=max(ans,sumk)
  print(ans)
if __name__=='__main__':
  
  
  main()

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

aves = [(i + 1) / 2 for i in P]
max_ave = sum(aves[0:K])
temp = max_ave
for i in range(N - K):
    temp -= aves[i]
    temp += aves[i + K]
    if temp > max_ave:
        max_ave = temp
print(max_ave)

Solution (Python):
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1

n,k = readInts()
p = readInts()

s = []
s.append((p[0]+1)/2)

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

ans = s[k-1]

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

print(ans)

Solution (Python):
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1

n,k = readInts()
p = readInts()

maxValue = sum(p[0:k])
be = maxValue
memo = p[0:k]
ans = 0
for i in range(1,n-k+1):
	be+=-p[i-1]+p[i+k-1]
	if maxValue<be:
		maxValue = sum(p[i:i+k])
		memo = p[i:i+k]

for i in range(k):
	ans+=(memo[i]+1)/2

print(ans)

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()
p = nl()

def exp(num):
  ret = (1+num)/2
  return ret

mx=0

pp = list(map(exp,p))
pd = [0]*(n+1)



for i in range(1,n+1):
  pd[i] = pd[i-1] + pp[i-1]




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

print(mx)

Solution (Python):

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
r = [0 for _ in range(n+1)]
ans = 0
for i in range(1,n+1):
    x = a[i-1]
    r[i] = r[i-1] + (x*(x+1))/2/x 
    if i+1 >=k:
        ans = max(ans,r[i]-r[i-k])
print(ans)

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
cnt=0
d=sum(p[:k])

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

cnt=max(cnt,d)

print((cnt+k)/2)

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):
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):


import itertools

n, k = map(int, input().split())
p_list = [int(x) for x in input().split()]
e_list = [None]*n

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

cumsum = list(itertools.accumulate(e_list))
ans = cumsum[k-1]

for i in range(k,n):
    _ = cumsum[i] - cumsum[i-k]
    if ans < _:
        ans = _

print(ans)

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
pp=list(map(f,p))
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+pp[i]
ans=0
for i in range(n-k+1):
    ans=max(ans,t[i+k]-t[i])
print(ans)