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


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


m = 0
midx = 0
for j in range(N-K+1):
    v = s[j+K] - s[j]
    if v > m:
        m = v
        midx = j
        
E = 0
for k in range(midx,midx+K):
    x = P[k]
    E += (1/x)*(x*(x+1)/2)
print(E)

Solution (Python):
def INT():
    return int(input())

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

def MI():
    return map(int, input().split())

N, K = MI()
p = LI()

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

for i in range(N):
    p[i] = E(p[i])
    
ans = sum(p[:K])
E_K = ans

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

print(ans)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:K]) 
maxsum = tmp

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

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

ans=0
sum_num=sum(p[:k])
for i in range(n-k+1):
    if i==0:
        sum_num = sum(p[:k])
    else:
        sum_num+=p[i+k-1]-p[i-1]
    ans=max(ans,sum_num)
print(ans)

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

P = [((x+1) * x / 2) / x for x in P]
A = list(accumulate(P))

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

print(ans)

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

A = list(accumulate(P))

largest = A[K-1]
point = 0
for i in range(K, N):
    if largest < A[i] - A[i-K]:
        largest = A[i] - A[i-K]
        point = i

ans = 0
for j in range(point - K + 1, point+1):
    p = P[j]
    ans += (((p + 1) * p) / 2) / p

print(ans)

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

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

ans = (a + K) / 2
print(ans)

Solution (Python):
import sys

N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[(1+p)/2 for p in P]
temp=sum(Q[:K])
ans=temp
for i in range(N):
  try:
    temp=temp-Q[i]+Q[i+K]
    ans=max(ans,temp)
  except:
    pass
else:
  print(ans)

Solution (Python):

import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, k = input_int_list()
    P = [0] + input_int_list()
    expected_sum = [0] * (n + 1)
    
    for i in range(1, n + 1):
        exp = (P[i] + 1) / 2
        expected_sum[i] = expected_sum[i - 1] + exp
    ans = 0
    
    for i in range(k, n + 1):
        ans = max(ans, expected_sum[i] - expected_sum[i - k])
    print(ans)
    return


if __name__ == "__main__":
    main()

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

res = 0

P2 = []
for i in P:
  P2.append(0.5 * (i + 1))
num = 0
for i in range(K):
  num += P2[i]
res = num
for i in range(1,N-K+1):
  temp = num + P2[i+K-1] - P2[i-1]
  if temp > res:
    res = temp
  num = temp
  
print(res)

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

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

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

probability=[]
sums=[0]
total=0
for i in range(N):
    num=0
    prob=1/P[i]
    for j in range(1,P[i]+1):
        num+=j*prob
    probability.append(num)
    total+=num
    sums.append(total)

ans=0
for j in range(N-K+1):
    if ans<sums[j+K]-sums[j]:
        ans=sums[j+K]-sums[j]

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

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

total=ans=sum(P[:K])
for n in range(K,N):
  total+=P[n]-P[n-K]
  ans=max(ans, total)

print(ans)

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

Q=[0]*(N+1)
for n in range(N):
  Q[n+1]=Q[n]+P[n]

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

print(ans)

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

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    p = LI()
    for i,x in enumerate(p):
        if x%2 == 0:
            x = x//2+0.5
        else:
            x = x//2+1
        p[i] = x

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

Solution (Python):


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

arr = [0]*n
for i in range(n):
  arr[i] = (A[i]+1)/2

s = sum(arr[:k])
ans = s
for j in range(n-k):
  s = s - arr[j] + arr[j+k]
  ans = max(s,ans)
print(ans)

Solution (Python):









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





















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


m = 0
for i in range(N - (K - 1)):
    _ = E[i + K] - E[i]
    if _ > m:
        m = _

print(m)

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

for n in range(N):
  sums += exp[n]
  ls.append(sums)

ans = 0
for n in range(N-K+1):

  ans_candidate = ls[n+K]-ls[n]

  if ans < ans_candidate:
    ans = ans_candidate 
print(ans)

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

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

ans = []

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

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

print(t/2)

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

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

total = sum(kitai[i] for i in range(k))
ans = total

for i in range(0, n-k):
  total = total - kitai[i] + kitai[i+k]
  if total > ans:
    ans = total

print(ans)

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,M=MAP()
L=LIST()
maxa=-(10**10)
sums=sum(L[:M])
maxa=max(maxa,sums)
for i in range(N-M):
  sums=sums-L[i]+L[i+M]
  maxa=max(maxa,sums)
print((maxa+M)/2)

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

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

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

ans = 0
for i in range(K,len(s)):
    ans = max(ans,s[i]-s[i-K])

if N == K:
    print(max(s))
    exit()

print(ans)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    v = []
    for i in range(N):
        v.append(sum_of_arithmetic_progression(1, 1, P[i]) / P[i])

    ans = 0.0
    tmp = 0.0
    for i in range(N):
        if i < K:
           tmp += v[i]
        else:
            tmp += v[i]
            tmp -= v[i - K]
        ans = max(ans, tmp)

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

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

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

ruisekiwa=[p_kitaiti[0]]

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

ans=ruisekiwa[k-1]

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

print(ans)

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

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

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

s = 0

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

s_max = s

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

print((s_max + K) / 2)

Solution (Python):
N, K = map(int,input().split())
P = [0]+list(map(int,input().split()))
for i in range(1,N+1):
  p = P[i]
  p = (1+p)/2
  P[i] = p+P[i-1]
ans = 0
for i in range(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()))


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


pe = []
for i in range(N):
    pe.append(calc(p[i]))

cs = [pe[0]] + [0]*(N-1)

for i in range(1, N):
    cs[i] = pe[i] + cs[i-1]

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

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t,k=ml()
n=ll()
ans=0
lol=0
for i in range(t):
    if(i>=k):
        lol+=((n[i]*(n[i]+1))//2)/n[i]
        lol-=((n[i-k]*(n[i-k]+1))//2)/n[i-k]
    else:
        lol+=((n[i]*(n[i]+1))//2)/n[i]
    ans=max(ans,lol)
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(1, N-K+1):
    s = s - p[i-1] + p[i+K-1]
    m = max(m, s)
print((m+K)/2)

Solution (Python):
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b
n,k=map(int,input().split())
p=Csum(list(map(int,input().split())))
ans=0
for i in range(n-k+1):
    ans=max(ans,p[i+k]-p[i])
print((ans+k)/2)

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

rui=[0]
for i in a:
  rui.append(rui[-1]+i)
hantei=0
for i in range(0,len(rui)-k):
  if hantei<=rui[i+k]-rui[i]:
    hantei=rui[i+k]-rui[i]
    l=i
    r=i+k
ans=0
for i in range(l,r):
  ans+=(a[i]+1)/2
  
print(ans)

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

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


def CalculateExpectedValu(n):
    bunbo = 1 / n
    ans = 0

    for i in range(1,n+1):
        ans = ans + (i*bunbo)

    return ans

number = 0
CumulativeSum = [0]

for i in P:
    number = number + CalculateExpectedValu(i)
    CumulativeSum.append(number)

ans = 0



for i in range(0 , (len(CumulativeSum)-K)):
    tmpans = CumulativeSum[i+K] - CumulativeSum[i]
    ans = max(ans, tmpans)

print(ans)

Solution (Python):
n,k=map(int,input().split())
li=list(map(int,input().split()))
kai=[0]
for i in range(1,1001):
  kai.append(kai[i-1]+i)
ka=[0]+[kai[i]/i for i in range(1,len(kai))]
lis=[ka[i] for i in li]

ans=sum(lis[:k])
mx=ans
for i in range(len(li)-k):
  ans-=lis[i]
  ans+=lis[i+k]
  mx=max(ans,mx)
print(mx)

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

import numpy as np

data = np.array(p) + 1

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

length_K_sums = Pcum[K:] - Pcum[0:-K]

print(np.max(length_K_sums)/2)

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

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
math = [0]*N
ans = 0
check = 0
for i,j in enumerate(p):
    math[i] += (j*(j+1)/2)/j
    if(i+1<=K):
        check += math[i]
    else:
        check += math[i]
        check -= math[i-K]
    ans = max(ans,check)
print(ans)

Solution (Python):
n,k=map(int,input().split())
a=[int(s) for s in input().split()]
b=[0]*k
c=0
v=[0]*n
v[0]=a[0]
for i in range(n-1):
    v[i+1]=v[i]+a[i+1]
mx=v[k-1]
for i in range(k,n):
    g=v[i]-v[i-k]
    mx=max(mx,g)  
    
print((mx+k)/2)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
E = [0] * N
for i in range(N):
    P = 0.5 * p[i] * (p[i] + 1)
    E[i] = P / p[i]
S = sum(E[:K])
s = S
for i in range(N - K):
    s -= E[i]
    s += E[i + K]
    S = max(S, s)
print(S)

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

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
gki = sum(a[0:k])
tmp = gki
rng = k
for i in range(k,n):
  tmp = tmp-a[i-k]+a[i]
  if tmp>gki:
    gki = tmp
    rng = i+1
  
E = 0
for i in a[rng-k:rng]:
  E += (i+1)/2
print(E)

Solution (Python):
n,k=map(int, input().split())
pn = list(map(int, input().split()))
ex_list = [(pn[i]+1)/2 for i in range(len(pn))]
ex_wa_list = []
wa = 0
for i in range(len(ex_list)):
    wa += ex_list[i]
    ex_wa_list.append(wa)
Ans_list = []
wa2 = 0
for i in range(n-k+1):
    if i == 0:
        wa2 = ex_wa_list[k-1]
    else:
        wa2 = ex_wa_list[k-1+i] - ex_wa_list[i-1]
    Ans_list.append(wa2)
print(max(Ans_list))

Solution (Python):
import sys


def resolve(in_):
    N, K = map(int, next(in_).split())
    A = map(int, next(in_).split())
    number_plus1 = list(i + 1 for i in A)

    v = [0] * N
    v[0] = sum(number_plus1[:K])
    for i, (before, after) in enumerate(zip(number_plus1, number_plus1[K:]), 1):
        v[i] = v[i - 1] - before + after

    expected = max(v) / 2

    return expected


def main():
    answer = resolve(sys.stdin.buffer)
    print(f'{answer:.12f}')


if __name__ == '__main__':
    main()

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()
P = inintl()

s = [0]*(n+1)
ans = 0

for i in range(n):
    s[i+1] = s[i]+(1 + (P[i]-1)*0.5)

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

print(ans)

Solution (Python):
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
P = [int(x) for x in sys.stdin.readline().rstrip().split()]



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

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

gmax = goukei
for i in range(N - K):
    goukei = goukei + kitaichi(P[K + i]) - kitaichi(P[i])  
    gmax = max(goukei, gmax)

print(gmax)

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

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

print(ans)

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

a = [0] * (N - K + 1)
a[0] = sum(P[:K])
for i in range(1, N - K + 1):
    a[i] = a[i - 1] - P[i - 1] + P[i + K - 1]
    
print((max(a) + K) / 2)

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

Solution (Python):

from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def ev(n):
    return 0.5*(n+1)


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

    p_ev = list(map(ev, p))

    s = np.cumsum(p_ev)
    s = np.insert(s, 0, 0)

    ans = []

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

    print(max(ans))


if __name__ == '__main__':
    main()

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

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
ma = s = sum(P[:K])
for i in range(N-K):
    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(((1+p[i])*p[i]/2)/p[i])

s = [0]*(N+1)
for i in range(1,N+1):
    s[i] = l[i-1]+s[i-1]

ans = 0
for i in range(K,len(s)):
    ans = max(ans,s[i]-s[i-K])

if N == K:
    print(max(s))
else:
    print(ans)

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

p = list(map(lambda x: (1+x)/2, p))
s = [0]
num = 0
for i in range(n):
  num += p[i]
  s.append(num)
l = []
for i in range(n - k + 1):
  l.append(s[i+k]-s[i])

print(max(l))

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
P = list(map(lambda x:int(x)+1, input().split()))

A = [0] + list(accumulate(P))

res = 0
for i in range(n-k+1):
    res = max(res, A[i+k] - A[i])
print(res/2.0)

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

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

que = [0]*(N+1)
for i in range(1,N+1):
    que[i] = l[i-1]+que[i-1]

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

if N == K:
    print(max(que))
else:
    print(ans)

Solution (Python):
n, k = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
E = []

for p in P:
    E.append(p*(p+1)/(2*p))

cumsumE = [0]
for e in E:
    cumsumE.append(cumsumE[-1] + e)

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

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

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


ans = 0
prev = sum(dice[:K])
ans = prev
for i in range(K,N):
  temp = prev-dice[i-K]+dice[i]
  ans = max(ans,temp)
  prev = temp
print(ans)

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

Solution (Python):
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
P2 = [(((P[i]+1)) / 2) for i in range(N)]



s = 0
init = 0
for i in range(K):
    s += P2[i] 
tmp = s
for i in range(1, N-K+1):
    tmp = tmp - P2[i-1] + P2[i+K-1]
    if s < tmp:
        s = tmp
        init = i

print(s)

Solution (Python):
N, K = map(int, input().split())
expectation = list(map(lambda x: (x+1) / 2, map(int, input().split())))
cur_expectation = sum(expectation[:K])
max_expectation = cur_expectation
for i in range(N - K):
    cur_expectation -= expectation[i]
    cur_expectation += expectation[i + K]
    if cur_expectation > max_expectation:
        max_expectation = cur_expectation
print(max_expectation)

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

PMAX = 1000
s = [0] * (PMAX + 1)
for i in range(PMAX):
    s[i+1] = s[i] + (i + 1)

e = [0] * (N + 1)
for i, p in enumerate(P):
    e[i+1] = e[i] + (s[p] / p)

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

Solution (Python):
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
  val+=a[K+i]
  val-=a[i]
  max_val=max(val,max_val)
print(max_val/2+K*0.5)

Solution (Python):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
expected = []
cumsum = []
for x in arr:
	sum = (x * (x + 1)) // 2
	ex = sum / x
	expected.append(ex)

sum = 0
maxi = 0
taken = 0
bad = 0
for x in expected:
	sum += x
	taken += 1
	if taken == k:
		 maxi = max(maxi, sum)
	elif taken > k:
		sum -= expected[bad]
		bad += 1
		maxi = max(maxi, sum)
print(maxi)

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

if '__main__' == __name__:
    resolve()

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

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

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

print(ans)

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

s=0
for i in range(k):
    s += P[i]

ms=s
for i in range(len(P)-k):
    s +=(P[i+k]-P[i])
    if s>ms :
        ms=s

print( (ms+k)/2)

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

s = 0
e = k
t = sum(p[0:k])

ans = 0
while True:
    ans = max(ans, t)
    if e == n:
        break
    t -= p[s]
    t += p[e]
    s += 1
    e += 1

print(ans / 2)

Solution (Python):
N,K=map(int,input().split())
P=list(map(int,input().split()))
L=[]
M=[0]
c=0
m=0
x=0
for i in range(200100):
    c+=i
    L.append(c)
for i in P:
    m+=L[i]/i
    M.append(m)
if N!=K:
    for i in range(N-K+1):
        x=max(M[K+i]-M[i],x)
else:
    x=M[K]-M[0]
print(x)

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

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

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

rwa = [0]*(len(p)+1)

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

wa = [0]*(N-K+1)
for i in range(len(wa)):
    wa[i] = rwa[K+i]-rwa[i]

t = wa.index(max(wa))

re = 0
for i in range(K):
    if p[t+i]%2 == 0:
        re += p[t+i]/2 +0.5
    else:
        re += p[t+i]//2 +1


print(re)

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

Solution (Python):
import itertools

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

exlis = []


for i in lis:
    a = (1+i)/2
    exlis.append(a)


nlis = list(itertools.accumulate(exlis))


ans  = nlis[k-1]
for j in range(n-k):
    tmp = nlis[j+k] - nlis[j]
    ans = max(ans, tmp)

print(ans)

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

c = sum(exp[:k])
cmax = c

for i in range(n-k):
    c -= exp[i]
    c += exp[i+k]

    if c > cmax:
        cmax = c

print(cmax)

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

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

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

ans = 0
for i in range(K,len(l)):
    ans = max(ans,a[i]-a[i-K])

if N - K == 0:
    print(max(a))
else:
    print(ans)

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

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

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

ans = 0
for i in range(K,len(l)):
    ans = max(ans,a[i]-a[i-K])

if N == 1 or N - K == 0:
    print(max(a))
else:
    print(ans)

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

arr = [(1 + m) / 2 for m in p]
ans = 0
sum = 0
for i in range(n):
	sum += arr[i]
	if i >= k: sum -= arr[i - k] 
	ans = max(ans, sum)
print(ans)

Solution (Python):
import itertools

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

a=[0]+list(itertools.accumulate(a))
ans=0

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

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


l = [[] for i in range(n)]
m = [[] for i in range(n - k + 1)]  

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


m[0] = sum(l[0:k])
ans = m[0]

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


print(ans)

Solution (Python):
nn, kk = list(map(int,input().split()))
pp = list(map(int,input().split()))

expectation = [0]*(nn-kk+1)
expectation[0] = sum(pp[0:kk])

for i in range(1,nn-kk+1):
    expectation[i] = expectation[i-1] - pp[i-1] + pp[i+kk-1]

print((max(expectation)+kk)/2)

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

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


if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    N,K = [int(i) for i in input().split()]
    P = [int(i) for i in input().split()]
    prev_K_sum = max_K_sum = sum(P[:K])
    start = 0
    for i in range(N-K):
        cur_K_sum = prev_K_sum - P[i] + P[i+K]
        if cur_K_sum > max_K_sum:
            start = i + 1
            max_K_sum = cur_K_sum
        prev_K_sum = cur_K_sum
    target = P[start:start+K]
    ans = sum([(num+1)/2.0 for num in target])
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
import itertools
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[]
for i in range(n):
    exp=(p[i]+1)/2
    l.append(exp)
cumsum=[0]+list(itertools.accumulate(l))
ans=0
for i in range(n-k+1):
    sum_num=cumsum[i+k]-cumsum[i]
    if sum_num>ans:
        ans=sum_num
print(ans)

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

Solution (Python):

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

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

print(ans)

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

Solution (Python):
memo = [0] * 200001 
def kitaichi(kazu):
    global memo
    ans = 0
    if memo[kazu] == 0:
        for i in range(1,kazu+1):
            ans += i * (1 / kazu)
        memo[kazu] = ans
    return memo[kazu]

n,k = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
max_p = 0
for j in range(k):
    ans += kitaichi(p[j])

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

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

import numpy as np

Q = np.cumsum(P)

R = np.pad(Q,K,'constant', constant_values=0)[:N]

a = np.argmax(Q-R)

ans = 0
for i in range(K):
    ans += (1.00+P[a-i])/2.00
print(ans)

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

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

pos = 0
n = m = sum(P[0:K])
for i in range(1,N):
    if i+K > N:
        break
    n = n - P[i-1] + P[K-1+i]
    if n > m:
        pos = i
        m = n

print((sum(P[pos:pos+K]) + K) / 2)