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 = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
ary = [0]*N
for i, p in enumerate(P):
    ary[i] = (p+1)*p/2/p
tmp = sum(ary[:K])
ans = tmp
for i in range(N-K):
    tmp = tmp-ary[i]+ary[i+K]
    ans = max(ans, tmp)

print(ans)

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

Solution (Python):
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(3, [1, 2, 2, 4, 5]), 7.0)

    def test_2(self):
        self.assertEqual(think(1, [6, 6, 6, 6]), 3.5)

    def test_3(self):
        self.assertEqual(think(4, [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]), 32.0)


def solve():
    k, p = read()
    result = think(k, p)
    write(result)


def read():
    n, k = read_int(2)
    return k, read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, p):
    prob = [0 for _ in range(len(p))]
    for i, elem in enumerate(p):
        prob[i] = (elem * (elem + 1)) / (2 * elem)
    prob = [0.0] + prob
    accumulated = [0.0 for _ in range(len(prob))]
    for i in range(len(prob)):
        if i == 0:
            continue
        accumulated[i] = accumulated[i - 1] + prob[i]

    maximum_expectation = -1
    for i in range(len(accumulated)):
        if i + k >= len(accumulated):
            break
        maximum_expectation = max(maximum_expectation, accumulated[i + k] - accumulated[i])
    return maximum_expectation


def write(result):
    print(result)


if __name__ == '__main__':
    
    solve()

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
p = inl()
sm = sum(p[:k])
mx = sm

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

Solution (Python):
def calc_kitai(n):
    return (n * (n + 1) / 2) * (1 / n)


N, K = map(int, input().split())
P = list(map(int, input().split()))
sumP = []
max_idx = None
max_val = -float('inf')
for i in range(N - K + 1):
    if i == 0:
        max_val = sum(P[i:i + K])
        max_idx = i
        prv_val = sum(P[i:i + K])
    else:
        if max_val < prv_val + P[i + K - 1] - P[i - 1]:
            max_val = prv_val + P[i + K - 1] - P[i - 1]
            max_idx = i
        prv_val = prv_val + P[i + K - 1] - P[i - 1]

ans = 0
for i in range(K):
    ans += calc_kitai(P[max_idx + i])
print(ans)

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

res=[]
for i in range(n):
    tmp=((p[i]*(p[i]+1))//2)/p[i]
    res.append(tmp)

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

print(ans)

Solution (Python):
nk = input().split(" ")
n = int(nk[0])
k = int(nk[1])
p = input().split(" ")
for i in range(n):
    p[i] = int(p[i])

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

tmp = max
for i in range(1, n+1-k):
    tmp -= p[i-1]
    tmp += p[i+k-1]
    if max < tmp:
        max = tmp

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

Solution (Python):
import sys
import itertools

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    ans = 0
    P2 = []
    for i in range(N):
        P2.append((P[i] / 2) * (P[i] + 1) / P[i])

    if N == 1:
        print(max(P2))
        return
    if N == K:
        print(sum(P2))
        return
    P3 = list(itertools.accumulate(P2))
    for i in range(N - K):
        ans = max(ans, P3[i + K] - P3[i])



    print(ans)


if __name__ == '__main__':
    main()

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

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

max = 0

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

print(max)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)

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

sk = sum(P[:K])
n = sum(P[:K])
for i in range(N):
    if i < K:
        continue

    n -= P[i - K]
    n += P[i]

    sk = max(sk, n)
    prev = n

ans = sk / 2. + K / 2.
print(ans)

Solution (Python):

import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s

n,k=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(n-k+1)
A=[0]*1100
sum_=0
for a in range(1,len(A)):
    sum_+=a
    A[a]=sum_/a
for a in range(k):
    S[0]+=A[P[a]]
for a in range(1,n-k+1):
    S[a]=S[a-1]
    S[a]+=A[P[k+a-1]]
    S[a]-=A[P[a-1]]
print(format(float(max(S)), '.20f'))

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

Solution (Python):
from itertools import accumulate

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

total = [0] * 1001
total[0] = None
total[1] = 1.0
for i in range(2, 1001):
    total[i] = total[i-1] + 0.5
for i in range(N):
    p[i] = total[p[i]]
p = [0] + list(accumulate(p))

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

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
max_p=max(p)
e=[-1 for _ in range(max_p+1)]


def calc_e(i):
    if(e[i]==-1):
        ei=(i+1)/2
        e[i]=ei
        return ei
    else:
        return e[i]

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

now_e=ans
for i in range(1,n-k+1):
    now_e-=calc_e(p[i-1])
    now_e+=calc_e(p[i+k-1])
    if(ans<now_e):
        ans=now_e
print(ans)

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

sm=0
for i in range(k):
    sm+=new_p[i]
mx=sm

for i in range(1,n-k+1):
    sm-= new_p[i-1]
    sm+= new_p[i+k-1]
    if mx < sm:
        mx=sm

print(mx)

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

B = [0]
for i in range(N):
    B.append(B[i] + P[i])

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

table = [0]*1001
for i in range(1, 1001):
    for j in range(1, i+1):
        table[i] += j * (1 / i)

ans = 0
for i in range(start, start+K):
    ans += table[P[i]]

print(ans)

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

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

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

for i, p in enumerate(P):
  P[i] = (1 + p) / 2
  
sum_ = sum(P[:K])
res = sum_

for i in range(K, N):
  sum_ = sum_ - P[i-K] + P[i]
  res = max(sum_, res)
  
print(res)

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

cur = sum(ex[:k])
ans = cur
for i in range(0, n - k):
	cur = cur + ex[i + k] - ex[i]
	ans = max(ans, cur)

print(ans)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
rui = [0] * (N + 1)

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

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

print(ans)

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

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

Solution (Python):
fact = [0]*1010
for i in range(1, 1010): fact[i] = fact[i-1]+i

n, k, *a = map(int, open(0).read().split())
a = list(map(lambda x:fact[x]/x, a))
ans = tmp = sum(a[:k])
for i in range(n-k):
    tmp -= a[i]
    tmp += a[i+k]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



def main():
    N, K = mis()
    A = lmis()
    tmp = sum(A[:K])
    tmp_max = tmp
    for i in range(K, N):
        tmp += A[i] - A[i-K]
        tmp_max = max(tmp_max, tmp)
    print((tmp_max+K)/2)


main()

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

pro = 0
for i in range(k):
    pro += arr[i]


ans = pro
for i in range(k,n):
    pro = pro + arr[i]-arr[i-k]
    if pro > ans:
        ans = pro


print((ans+k)/2)

Solution (Python):
import sys
from itertools import accumulate
n, k = [int(i) for i in sys.stdin.readline().split()]
p_ls = [int(i) for i in sys.stdin.readline().split()]
ls = []
for i, p in enumerate(p_ls, 1):
    ls.append((1 + p) / 2)
ans = 0
cur = 0
for i, l in enumerate(ls):
    if i >= k:
        cur -= ls[i-k]
    cur += l
    ans = max(ans, cur)
print(ans)

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

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

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

exp_val = sum(exp[:K])

max_ = exp_val
for i in range(K, N):
    exp_val += exp[i]
    exp_val -= exp[i - K]

    max_ = max(max_, exp_val)

print(max_)

Solution (Python):
n, k = map(int, input().split(" "))
ps = list(map(int, input().split(" ")))
k_sum = sum(ps[:k])
tmp_max = k_sum

for next_idx in range(k, n):
    rm = next_idx - k
    val_rm = ps[rm]
    val_add = ps[next_idx]
    k_sum = k_sum - val_rm + val_add
    tmp_max = max(tmp_max, k_sum)
print((tmp_max + k) / 2)

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

p = [(x+1)/2 for x in map(int, input().split())]

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

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

print(ans)

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


ans = 0
now = 0
sum = 0
E = [0] * n

for i in range(n):
    E[i] = 0.5 + p[i]/2
    now += E[i]
    if(i == k-1):
        ans = now
    elif(i >= k):
        now -= E[i-k]
        ans = max(ans,now)

print(ans)

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

S = [0]*N

for i in range(K):
    S[0] += p[i]

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

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

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

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [0.0]
for i in range(N):
    ans.append(ans[-1]+A[i]/2.0+0.5)
ANS = 0

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

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

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

Solution (Python):
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    n, k = get_list()
    li = get_list()
    ans = sum(li[:k])
    sm = ans
    for i in range(n-k+1):
        ans = max(ans, sm)
        if i<n-k:
            sm += li[i + k] - li[i]
    print((ans+k)/2)



''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right

import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()

print(*out, sep='\n')

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

sum_k = 0
for i in range(k):
    sum_k += p_list[i]
sum_max = sum_k
for i in range(k, n):
    sum_k -= p_list[i-k]
    sum_k += p_list[i]
    if(sum_k > sum_max):
        sum_max = sum_k
print(sum_max)

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

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

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

Solution (Python):

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


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

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

print((max_ans + K)/2)

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

next_end = K

num = sum(P[:next_end])

max_num = num

for start in range(1, N - K + 1):
    num -= P[start - 1]
    num += P[next_end]
    max_num = max(num, max_num)
    next_end += 1

print((max_num + K) / 2)

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
sum_i = [0]
for pi in P:
    s = (pi * (1 + pi)) / 2 / pi
    sum_i += [s + sum_i[-1]]

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

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

summation = [0] * 1001
expected = [0] * 1001
for i in range(1000):
    summation[i + 1] = summation[i] + (i + 1)

for i in range(1, 1001):
    expected[i] = summation[i] / i

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + expected[P[i]]

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

print(ans)

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
e = []
for i in range(N):
    x = p[i] * (p[i]+1) / (2 * p[i])
    e.append(x)

ans = 0
tmp = 0
for i in range(K):
    tmp += e[i]
if tmp > ans:
    ans = tmp
for i in range(N-K):
    
    tmp -= e[i]
    tmp += e[i+K]
    if tmp > ans:
        ans = tmp
print(ans)

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

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

print(m)

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

s = sum(dice[:k])
dice2 = [s]

for i in range(n - k):
    s += dice[i+k] - dice[i]
    dice2.append(s)
print(max(dice2))

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

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

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

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

e = []
for v in p:
    if v % 2 == 0:
        e.append(((v+1)*(v//2)) / v)
    else:
        e.append(((v+1)*(v//2) + (v+1) // 2) / v)

e_sum = [0]

for i in range(len(e)):
    e_sum.append(e_sum[i] + e[i])

ans = 0

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

print(ans)

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

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

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)
ans = 0
tmp = sum(l[:K-1])
p = l[0]
idx = 0
for i in range(K-1, N):
    tmp += l[i]
    
    ans = max(ans, tmp)
    p = l[idx]
    tmp -= p
    idx += 1
print(ans)

Solution (Python):
a,b = map(int,input().split())
p = list(map(int,input().split()))
ans = sum(p[:b])
count = ans
for i in range(1,a-b+1):
  count = count-p[i-1]+p[i+b-1]
  if count > ans:
    ans = count
print((ans+b)/2)

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

S = sum(p[0:K])
max_S = S
for i in range(N - K):
    S += p[i + K] - p[i]
    max_S = max(S, max_S)
print((max_S + K) / 2)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, A):
    B = deque(A[:K])
    S = sum(A[:K])
    ms = S
    mi = 0
    for i in range(K, N):
        S -= B.popleft()
        S += A[i]
        B.append(A[i])
        if S > ms:
            ms = S
            mi = i - K + 1

    ans = 0
    for i in range(mi, mi+K):
        ans += (A[i] + 1) / 2
    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

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

ans = sum(p_ave[:K])
temp, tempmax = 0, 0

for i in range(N-K):
    temp += p_ave[i+K] - p_ave[i]
    if temp > tempmax:
        tempmax = temp

print(ans + tempmax)

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

Solution (Python):
N, K, *P = map(int, open(0).read().split())

A = [0]
for i in range(1, 1001):
    A.append(A[-1] + i)
B = [0] + [A[i] / i for i in range(1, 1001)]

Q = [B[p] for p in P]
ans = [sum(Q[:K])]
for i in range(N - K):
    ans.append(ans[-1] - Q[i] + Q[i + K])
    
print(max(ans))

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

cumsum = [0] * (N+1)

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

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

Solution (Python):


def main():
    n, k = map(int, input().split())
    nums = list(map(int, input().split()))
    
    for i in range(len(nums)):
        nums[i] = (nums[i] + 1) / 2
    
    sumv = sum(nums[:k])
    maxv = sumv
    for i in range(len(nums) - k):
        f = nums[i]
        l = nums[i + k]
        sumv = sumv - f + l
        if sumv > maxv:
            maxv = sumv
    print(maxv)
main()

Solution (Python):
import numpy as np
N, K = map(int, input().split())
plist = list(map(int, input().split()))
kitaiti = np.array([(0.5*(p+1)) for p in plist])
ans = 0
val = sum(kitaiti[:K])
ans = max(ans, val)
for i in range(1, N-K+1):
    
    val -= kitaiti[i-1]
    val += kitaiti[i+K-1]
    ans = max(ans, val)
print(ans)

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

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

l = 0
r = K

maxl = l
maxr = r

s = sum(p[l:r])
maxs = s

for i in range(N-K):
    s -= p[i]
    s += p[i+K]
    if s > maxs:
        maxl = i+1
        maxr = i+K+1
        maxs = s

res = 0
for i in range(maxl, maxr):
    res += p[i]/2+0.5

print(res)

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

def cumsum(s):
    n = len(s)
    cs = [0] * (n+1)
    for i in range(n):
        cs[i+1] = cs[i] + s[i]
    return cs

pc = cumsum(p)
nc = cumsum(range(1, 1001))
mx = 0
s = 0

for i in range(n-k+1):
    sm = pc[i+k] - pc[i]
    if mx < sm:
        s = i
        mx = sm

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

print(ans)

Solution (Python):
a = [int(i) for i in input().split()]
b = [(int(i)+1)/2 for i in input().split()]

he = sum(b[:a[1]])
maxer = he
for i in range(a[0] - a[1]):
    he -= b[i]
    he += b[i + a[1]]
    maxer = max(he, maxer)

print(maxer)

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

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

B = [0]
for i in range(N):
  B.append(B[-1]+A[i])

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

print(ans)

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

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

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

tmp = sum(p[0:k])

ans = tmp

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

print(0.5*k+ans/2)

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

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = list(map(lambda x : (x + 1) / 2, P))
cur = sum(P[0 : K])
ans = cur

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

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

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

x=[0]*N
y=[0]*(N+1-K)

for i in range(N):
  x[i]=0.5*(p[i]+1)
for i in range(K):
  y[0]+=x[i]
for i in range(N+1-K):
  if i!=0:
    y[i]=y[i-1]-x[i-1]+x[i-1+K]
print(max(y))

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

buf=0
for i in range(k):
    buf+=a[i]

ans = buf

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

print(ans)

Solution (Python):


def main():
    N, K = [int(s) for s in input().split()]
    p = [int(s) for s in input().split()]
    s = sum(p[:K])
    res = s
    for i in range(1,N):
        if i+K > N:
            break
        s = s + p[i+K-1]
        s = s - p[i-1]
        res = max(s,res)
    print((res+K)/2)

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] + 1) / 2

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

Solution (Python):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''

gi = lambda : list(map(int,input().split()))
n, k = gi()
a = gi()
ans = 0
temp = 0
for j in range(k):
	ans += (a[j] * (a[j] + 1)) / (2 * a[j])
temp = ans
for j in range(k, n):
	temp -= (a[j - k] * (a[j - k] + 1)) / (2 * a[j - k])
	temp += (a[j] * (a[j] + 1)) / (2 * a[j])
	ans = max(ans, temp)
print(ans)

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

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

Solution (Python):




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

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

dice = [0] * 1001
for i in range(1,1001):
    dice[i] = dice[i-1] + i

ans = 0
tmp = 0
for i in range(N):
    if i < K-1:
        tmp += dice[P[i]] / P[i]
        
    elif i == K-1:
        tmp += dice[P[i]] / P[i]
        
        ans = max(ans, tmp)
    else:
        tmp += dice[P[i]] / P[i]
        tmp -= dice[P[i-K]] / P[i-K]
        
        ans = max(ans, tmp)
        
        

print(ans)

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

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