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):
import numpy as np
from scipy import signal

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = (P + 1) / 2

    t = np.ones((K))

    print(np.amax(
        signal.fftconvolve(
            e,
            t
        )
    ))

if __name__ == "__main__":
    main()

Solution (Python):
def summ(a):
    for i in range(1,a):
        a += a-i
    return a

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

s = [0]
for i in range(len(p)):
    s.append(s[i] + p[i])

max_value = 0

for i in range(0,len(s)-k):
    if(s[i+k] - s[i] > max_value):
        max_value = s[i+k] - s[i]
        max_start = i

ans_pre = []

for j in range(k):
    ans_pre.append(p[max_start + j])

ans = 0.0

for i in range(len(ans_pre)):
    ans += ((ans_pre[i]*(1+ans_pre[i]))/2)/ans_pre[i]
print(ans)

Solution (Python):

N, K = map(int, input().split())
lst = list(map(int, input().split()))
lst1 = [(lst[0] + 1) / 2]
ma = 0
for i in range(1, len(lst)):
    lst1.append(lst1[i-1] + ((lst[i]+1) / 2))
    if (i >= K):
        ma = max(ma,lst1[i] - lst1[i-K])
ma = max(ma,lst1[K-1])
print(ma)

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

history = {}

top3 = []

result = 0

def calc_expect_sum(targets):
    return sum( (p+1) * 0.5 for p in targets)

prev_sum = calc_expect_sum(ps[0:0+k])
result = 0

if n == k:
    print(calc_expect_sum(ps))
else:
    for i in range(1,n-k+1):
        prev = ps[i-1]
        current = ps[i+k-1]
        diff = (current - prev) * 0.5
        new = prev_sum + diff
        if new > result:
            result = new
        prev_sum += diff
    
    print(result)

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

m=sum(s[0:k])
r=[m,]
b=m

for i in range(n-k):
  b=b-s[i]+s[i+k]
  r.append(b)
r.sort()
print((r[-1]+k)/2)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_i=0
ret = 0
p_s=sum(p[0:k])
s_max=p_s
for i in range(n-k):
  p_s=p_s-p[i]+p[i+k]
  if s_max<p_s:
    s_max=p_s

print(s_max/2+k/2)

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

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

Solution (Python):
n, k = map(int, input().split())
pis = list(map(int, input().split()))
sum_max = 0
sum_cd = 0
for i in range(k):
  sum_max += pis[i]
  sum_cd += pis[i]
for j in range(1,n-k+1):
  sum_cd -= pis[j-1]
  sum_cd += pis[j+k-1] 
  if sum_cd > sum_max:
    sum_max = sum_cd
expect = sum_max/2 + k / 2
print(expect)

Solution (Python):
N, K = [int(n) for n in input().split(" ")]
lst = [int(n) for n in input().split(" ")]

sum_max = 0
temp = 0

for i in range(K):
    temp += (lst[i]+1)/2
    sum_max = temp
for j in range(0,N-K):
        temp += (lst[j+K]-lst[j])/2
        if temp > sum_max:
            sum_max = temp
            
print(sum_max)

Solution (Python):
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    if type(s) != type('str'):
        s=str(s)

    sys.stderr.write(s+'\n')
    return

def expected_value(n):
    ans = 0

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

    
    return ans

def main():
    n, k = map(int, input().split())
    Ps = list(map(int, input().split()))
    
    Cs = [0]*n
    for i in range(n):
        if i == 0:
            Cs[i] = Ps[i]
        else:
            Cs[i] = Cs[i-1] + Ps[i]
    
    Ds = list()
    mi = -10**9
    mix = 0
    for i in range(n-k+1):
        if i == 0:
            Ds.append(Cs[i+k-1])
        else:
            Ds.append(Cs[i+k-1] - Cs[i-1])

        if Ds[i] > mi:
            mi = Ds[i]
            mix = i

    
    
    v = int()
    for i in range(k):
        v += expected_value(Ps[mix+i])
        
    print(v)

    return

if __name__ == '__main__':
    main()

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

Solution (Python):
N,K = map(int,input().split(" ")[0:2])
p = list(map(int,input().split(" ")))

ret = []
s0 = sum(p[0:K-1])
for x in range(0,N-K+1):
    s0 = s0 + p[x+K-1]
    ret.append(s0)
    s0 = s0 - p[x]
print((max(ret)+K)/2)

Solution (Python):


def main():
    n,k = map(int, input().split())
    l = list(map(mean, input().split()))
    out = sum(l[:k])
    result = out

    for i in range(1, len(l)-(k-1)):
        result = result - l[i-1] + l[i+k-1]

        if out < result:
            out = result

    print(out)

def mean(x):
    x = int(x)
    return x * (x+1) / (2 * x)

if __name__ == "__main__":
    main()

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

mx = sum(ps[:k])
sm = sum(ps[:k])
for i in range(k, n):
  sm += ps[i] - ps[i-k]
  if sm > mx:
    mx = sm
print(mx)

Solution (Python):
n, k  = map(int, input().split())
L = list(map(int, input().split()))
E = []
for i in range(len(L)):
  E.append((1+L[i])/2)
v = 0
for i in range(k):
  v += E[i]
S = [v]  
for i in range(k, len(E)):
  v = v + E[i] - E[i-k]
  S.append(v)
print(max(S))

Solution (Python):
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=0
import numpy
ll=numpy.cumsum(l)
ans=ll[k-1]
for i in range(0,n-k):
    ans=max(ll[i+k]-ll[i],ans)
ans=ans+k
print(float(ans)/2)

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

res=[]

res.append((sum(range(1,p[0]+1)))/p[0])

for i in range(1,N):
    res.append(res[i-1]+1+0.5*(p[i]-1))
ans=res[K-1]

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

Solution (Python):
from itertools import accumulate

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

new_p = []
temp = []
for i in p:
    new_p.append(((i * (i + 1)) / 2) / i)
q = [0] + new_p
q = list(accumulate(q))

for i in range(len(q) - k):
    temp.append(q[i + k] - q[i])
print(max(temp))

Solution (Python):
import queue
import copy
import math
from collections import deque
import bisect


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


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

expects = []
max_e = 0
prev_e = 0

for p, i in zip(pn, range(0, n)):
    e = (((1 + p) * p) // 2) / p
    expects.append(e)
    if i + 1 == k:
        max_e = sum(expects)
        prev_e = max_e
    elif i + 1 > k:
        current_e = prev_e + expects[-1] - expects[i-k]
        max_e = max(max_e, current_e)
        prev_e = current_e
    else:
        continue

print(max_e)

Solution (Python):

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

n = a[0]
k = a[1]
p = list(map(int,input().split()))

e = [(pi+1)/2 for pi in p]

ret2 = []
b = 0.0
for j in range(k):
        b += e[j]
ret2.append(b)

for i in range(n-k):
        ret2.append(ret2[i] - e[i] + e[i+k])

ret=ret2

ret.sort()
print(ret[n-k])

Solution (Python):
import numpy as np

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

last_value = 0
l = [0]

for head, tail in zip(p, p[K:]):
    now = tail - head + last_value
    l.append(now)
    last_value = now
max_index = np.argmax(l)
max_sum = sum(p[max_index : max_index + K])
print((K + max_sum) / 2)

Solution (Python):
from itertools import accumulate

n,k = map(int, input().split())
p = list(map(int, input().split()))
acc = list(accumulate([i for i in range(max(p)+1)]))
ap = [0] + list(accumulate(p))
mx = 0
pos = 0
for i in range(n-k+1):
    if mx < ap[i+k] - ap[i]:
        mx = ap[i+k] - ap[i]
        pos = i
ans = 0
for i in range(pos,pos+k):
    ans += acc[p[i]] / p[i]
print('{:.10f}'.format(ans))

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

def calc(n):
  return sum(range(1, n + 1)) / n

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

max_value = -1
max_index = -1


for i in range(N - K + 1):
  s = sums[i+K] - sums[i]
  
  
  max_value = max(max_value, s)
  if max_value == s:
    max_index = i

print(max_value)

Solution (Python):
def kitaichi(a):
    return ((1+a)*a/2)/a

n, k = map(int, input().split())
p = [int(_) for _ in input().split()]
dp = [0] * n
dp[0] = p[0]
cnt = 1

maxi = 0
idx = 0

for i in range(1, n):
    if cnt < k:
        dp[i] = p[i] + dp[i-1]
        cnt += 1
    else:
        dp[i] = p[i] + dp[i-1] - p[i-k]
    if maxi < dp[i]:
        maxi = dp[i]
        idx = i

ans = 0
for i in range(idx-k+1, idx+1):
    ans += kitaichi(p[i])

print(ans)

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

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

ans = sum(p[:k])
ans_tmp = copy.copy(ans)

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


print((ans+k)/2)

Solution (Python):

import numpy as np
N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
p = (p + 1) / 2
cumsum = np.cumsum(np.array(p))
tmp = np.pad(cumsum[:-K], [K, 0], 'constant')
print((cumsum - tmp).max())

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

import numpy as np

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

N, K  = data[:2]
P = data[2:] + 1

Pcum = np.zeros(N + 1, np.int64)
Pcum[1:] = P.cumsum()

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

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

cnt=0
ans=0
buf=0
buf_2=0
q=deque([])
cnt=0
for i in range(N):
    cnt+=1
    buf=P[i]*(P[i]+1)//2/P[i]
    q.append(buf)
    buf_2+=buf
    if cnt>=K:
        if ans<buf_2:
            ans=buf_2
        buf_2-=q.popleft()
    
    
    
    
print(ans)

Solution (Python):

N,K = map(int,input().split())
p = list(map(int, input().split()))
S = [0]*N
s = 0
s_t = 0
S[0] = (1+p[0])/2

if N == 1:
    print(S[0])
    exit()
else:
    pass

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

if N == K:
    print(S[N-1])
    exit()
else:
    pass

for j in range(N-K):
    s_t = S[j+K]-S[j]
    if s_t >= s:
        s = s_t
    else:
        pass

print(s)

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

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



maxValue = -100100100
anker = -99

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

print(ans)

Solution (Python):


import numpy

def main():
  n, k = map(int, input().strip().split())
  Ps   = numpy.array(input().strip().split(), dtype=int)
  Es   = numpy.zeros(n+1)
  max = -1
  for i, P in enumerate(Ps):
    Es[i] = 0.5 * (P+1) + Es[i-1]
  max = -1
  for i in range(n-k+1):
    x = Es[i+k-1] - Es[i-1]
    if max < x:
      max = x
  print(max)

if __name__=='__main__':
  main()

Solution (Python):
N, K = map(int, input().split())
listp = tuple(map(int, input().split()))
bc =sum(listp[0:K])
b = sum(listp[0:K])
for n in range(1,N-K+1):
    b = b - listp[n-1]+listp[n+K-1]
    
    if b > bc:
        bc = b
    else:
        pass    
    
print((bc+K)/2)

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

Solution (Python):
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans



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

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

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

mat = -1
for i in range(n-k+1):
    nowsum = -sums[i] + sums[i+k]
    
    if(nowsum>mat):
        mat = nowsum

print(mat/2+k/2)

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

e = []
for i in p:
    e.append(1+i)

l = 0
s = sum(e[l:k-1])
t = sum(e[l:k-1])
for i in range(n-k):
    tmp = t + e[i+k] - e[i]
    t = t + e[i+k] - e[i]
    if tmp > s:
        s = tmp
        l = i + 1

print(sum(e[l:l+k])/2)

Solution (Python):
import numpy as np

def dice():
    n, k = map(int, input().split())
    p = np.asarray(list(map(int, input().split())))
    pp = np.zeros(n)
    for i in range(n):
      pp[i] = p[i]*(p[i]+1)/(2*p[i])
    ans = sum(pp[0:k]) 
    tmp = sum(pp[0:k])
    for i in range(1, n-k+1):
        tmp = tmp - pp[i-1] + pp[i+k-1]
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == '__main__':
    dice()

Solution (Python):
N,K=map(int,input().split())
P=list(map(int,input().split()))
ans=sum(P[:K])/2+0.5*K
A,S=[0]*N,[0]*N
A[0]=S[0]=P[0]
for i in range(N-1):
    A[i+1]=P[i+1]
    S[i+1]=S[i]+A[i+1]

for i in range(N-K):
    tmp=(S[K+i]-S[i])/2+0.5*K
    if ans<tmp:
        ans=tmp
print(ans)

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
saidai = 0
wa =[None]*n
wa_2 = 0
gokei = 0
for i in range(n):
    gokei += p[i]
    wa[i] = gokei
saidai = wa[k-1]
for j in range(n-k):
    wa_2 = wa[j+k]-wa[j]
    if wa_2 > saidai:
        saidai = wa_2
kitai = (1/2)*(k+saidai)
print(str(kitai))

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

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

sum_k = sum(P[:k])
temp_sum_k = sum_k 

for i in range(n-k):
  temp_sum_k = temp_sum_k+P[i+k]-P[i]
  if sum_k < temp_sum_k:
    sum_k = temp_sum_k

print((sum_k+k)/2)

Solution (Python):
N,K = map(int,input().split())
p = list(map(int,input().split()))
result = 0
p_t = [0]
for i in range(N):
    p_t.append(p[i]+p_t[i])
ans = p_t[K] - p_t[0]

for i in range(N-K):
    tmp = p_t[i+1+K] - p_t[i+1]
    if ans < tmp:
        ans = tmp
print((ans+K)/2)

Solution (Python):
import sys
from pprint import pprint

def solve(n, k, p):
    acum_E = [0]
    sum_E = 0
    for i, p_i in enumerate(p):
        sum_E += (1.0 + p_i)/2 
        acum_E.append(sum_E)
    
    
    ans = 0
    for i in range(n - k + 1):
        
        ans = max(ans, acum_E[i + k] - acum_E[i])
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)

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

for p_item in p:
  B.append(float((p_item+1)/2))
  
Max = sum(B[:K])
tmp = sum(B[:K])

for i in range(len(B)-K):
    tmp = tmp - B[i] + B[i+K]
    if Max < tmp:
      Max = tmp

print(Max)

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

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

print(ans)

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans= 0
tmp=0
sump=sum(p[0:k])
for i in range(n-k):
    sump=sump+p[i+k]-p[i]
    
    if sump>tmp:
        
        tmp = sump
        ans= i+1
anss=0
for j in p[ans:ans+k]:
    anss+=(j+1)/2


print(anss)

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

import itertools as its

def pin(type=int):
    return map(type,input().split())

def worstdata():
    a=0
    return a

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



n,k=(pin())
S=list(pin())
debug(S)
s=([comp(S[_]) for _ in range(n)])
ans=0

x=list(its.accumulate(s))


for a in range(k):
    ans=x[k-1]

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

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

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

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

m = 0
M = 0
for i in range(n-k+1):
    if i==0:
        for j in range(k):
            m += ls_mu[j]
        M += m
    else:
        l = ls_mu[i-1]
        r = ls_mu[i+k-1]
        m = m - l + r
        M = max(m,M)

print(M)

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

Solution (Python):
N,K=map(int,input().split())
P=list(map(int,input().split()))
X=0
for k in range(K):
	X+=P[k]
Y=X
for n in range(1,N-K+1):
	Y=Y+P[n+K-1]-P[n-1]
	X=max(X,Y)
print((X+K)/2)

Solution (Python):
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
tmp = sum(P[:K])
high = tmp
e = 0
for i in range(1, N-K+1):
    tmp -= P[i-1]
    tmp += P[i+K-1]
    if tmp > high:
        high = tmp
        e = i
exp = 0
for p in P[e:e+K]:
    exp += sum(range(1,p+1)) / p

print(exp)

Solution (Python):
import numpy as np

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

s = (K+ np.sum(P[:K]))/2
ans = s
for i in range(1,N-K+1):
    s = s - P[i-1]/2 + P[i+K-1]/2
    if s > ans:
        ans = s
print(ans)

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

Solution (Python):
import sys

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

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

if N == K:
    myans = 0
    for n in range(N):
        myans += (mylist[n]+1)/2
    print(myans)
    sys.exit()

if K == 1:
    print((1+max(mylist))/2)
    sys.exit()
    
dp = [0 for n in range(N)]

for i in range(K):
    dp[i] = (mylist[i]+1)/2
dp[K-1] = sum(dp[0:K])

myans = -999999999
for n in range(K,N):
    dp[n] = (mylist[n]+1)/2 + dp[n-1] - (mylist[n-K]+1)/2 
    if myans < dp[n]:
        myans = dp[n]

        
print(myans)

Solution (Python):
import math
import itertools


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

def s(n):
    if(n==1):
        return 1
    else:
        return (n*(n+1))/2



for i in range(n):
    point.append(s(p[i])/p[i])
    if i==0:
        rui.append(point[0])
    else:
        rui.append(rui[i-1]+point[i])


m = 0
a = 0
for i in range(n-k+1):
    if i==0:
        a = rui[i+k-1]
    else:
        a = rui[i+k-1]-rui[i-1]
    
   
    if a > m:
        m = a





print(m)

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

p_cum = []
temp=0
for elm in p:
    temp+=elm
    p_cum.append(temp)

max=0
temp=0
for k in range(N-K+1):
    temp_max = (p_cum[k+K-1]-temp+K)/2.0
    if max < temp_max:
        max=temp_max
    temp=p_cum[k]
print(max)

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


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


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

r = k
cur_value = max_value
for l in range(1, n - k + 1):
    cur_value = cur_value - calc_mean(p[l - 1]) + calc_mean(p[r])
    max_value = max(max_value, cur_value)
    r += 1

print(max_value)

Solution (Python):


import numpy as np


def main():
    N, K = map(int, input().split())
    ps = np.array(list(input().split()), dtype=int)
    ps = (ps + 1) / 2

    s_list = [0 for _ in range(N)]

    left = 0
    right = K
    s_list[0] = sum(ps[left:right])

    maximum = s_list[0]

    for i in range(1, N):
        left = ps[i-1]

        p_right = K + i - 1
        if p_right >= N:
            right = 0
        else:
            right = ps[p_right]

        s_list[i] = s_list[i-1] - left + right
        maximum = max(maximum, s_list[i])

    return maximum


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

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

s = sum(p[:k]) + k
t = s
for a, b in zip(p, p[k:]):
    t = t - a + b
    s = max(s, t)

print(s/2)

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

MAX = 0

dp = [0] * N
for i in range(N - K + 1):
    if i < 1:
        dp[i] = 0.5 * (sum(p[:K]) + K)
    else:
        dp[i] = dp[i - 1] - 0.5 * p[i - 1] + 0.5 * p[i + K - 1]

    MAX = max(MAX, dp[i])
print(MAX)

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


SUM = [0]*N
SUM[0] = sum(P[0:K])

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

EXP_V = (K + max(SUM))/2
print(EXP_V)

Solution (Python):
n,k = map(int, input().split())
p = list(map(int, input().split()))
m = max(p)
h = [0]*(m+1)
h[1] = 1
for i in range(1,m):
    h[i+1] = h[i]+0.5
ans = sum = 0
for i in range(n):
    if i>=k:
        sum = sum-h[p[i-k]]+h[p[i]]
        if ans<sum: ans=sum
    else:
        sum += h[p[i]]
        if i==k-1: ans=sum
print(ans)

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

a = sum(p[0:k])
b = a
c = a

for i in range(n-k):
    b -= p[i]
    b += p[i+k]
    if c < b:
        c = b
        
print((c+k) / 2)

Solution (Python):
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
cnt = sum(p[0:k])
tmp = 0
for i in range(k, n):
    if p[i] + tmp - p[i-k] > 0:
        cnt += p[i]-p[i-k]+tmp
        tmp = 0
    else:
        tmp += p[i]-p[i-k]
print((cnt+k)/2)

Solution (Python):

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

sum = 0
max = 0

for i in range(K):
    sum += array[i]
    max = sum

for i in range(K, N):
    sum += array[i] - array[i - K]
    if sum > max:
        max = sum

E = (max + K) / 2
print(E)

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

    r = [0]
    for i in range(N):
        r.append(r[i]+p[i])


    ans = 0
    max_i = 0
    max_value = 0
    for i in range(1,N-K+1):
        t = r[i+K]-r[i]
        if max_value < t:
            max_value = t
            max_i = i



    for i in range(max_i, max_i+K):
        if len(p) <= i:
            break
        n = p[i] + 1
        ans += (n*(n-1)//2) / (n-1)
    
    print(ans)

if __name__ == '__main__':
    main()

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

def expect(x):
    return ((x*(x+1))//2) / x

for p in P:
    e.append(expect(p))

ans = sum(e[:K])
tmp = ans

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

print(ans)

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

Solution (Python):
s=[0]
for i in range(1000):
    s.append(s[i]+i+1)
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[0]
for i in range(n):
    l.append(l[i]+p[i])
tmp=0
at=n-k
for i in range(n-k+1):
    if l[i+k]-l[i]>tmp:
        tmp=l[i+k]-l[i]
        at=i
ans=0
for i in range(k):
    ans+=s[p[at+i]]/p[at+i]
print(ans)

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

m=0

for i in range(0,K):
    m=m+p[i]+1

A=[]
A.append(m)

if N==K:
    print(A[0]/2)
else:
    for i in range(1,N-K+1):
        s=A[i-1]-p[i-1]+p[i+K-1]
        A.append(s)
    print(max(A)/2)

Solution (Python):
import sys
from io import StringIO
import unittest

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

    loop=n-k+1

    ms=0
    bef=0
    for i in range(loop):
        tmp=0
        if i ==0:
            for j in range(k):
                tmp+=p[i+j]/2+1/2
            if tmp > ms:
                ms = tmp
        else:
            tmp=bef
            tmp-=(p[i-1]/2+1/2)
            tmp+=(p[i+k-1]/2+1/2)
            if tmp > ms:
                ms = tmp
        bef=tmp

    print(ms)

    return

resolve()

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N, K = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))

P = np.array(P, dtype=float)
E = (P + 1) / 2
cs = E.cumsum()

ans = cs[K - 1]
if K < N:
    ans = max(ans, (cs[K:] - cs[:-K]).max())
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n,m=IA()
a=list(IA())
ans=float(0)

N=int(200005)
s=[int(0) for i in range(N)]

s[1]=a[0]
for i in  range(1,n):
    s[i+1]=s[i]+a[i]
   

    
for i in  range(1,n+1):
   

    if i+m-1>n:break
    
    sum1=(s[i+m-1]-s[i-1]+m)/2

    
    ans=max(ans,sum1)
    
print("%.12lf"%ans)

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

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

list = [goukei]

for j in range(1, n-k+1):
    list.append(list[j-1] - p[j-1] + p[j+k-1])

ind = list.index(max(list))

for j in range(ind, ind+k):
    kitai = kitai + (p[j]+1)/2
'''
print(max(list))
print(p)
print(list)
print(ind)
'''
print(kitai)

Solution (Python):
from collections import deque

def sum_to(n):
    return (n+1)*int((n/2))+(n%2)*((n+1)/2)

def expected(n):
    return sum_to(n) / n

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

max_sum = 0
cur_sum = 0
select = deque()
c = 0
for i in P:
    e_val = expected(i)
    select.append(e_val)
    cur_sum += e_val
    if len(select) == K:
        if cur_sum > max_sum:
            max_sum = cur_sum
        cur_sum -= select.popleft()

print(max_sum)

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

Solution (Python):
nk = input().split(' ');
n = int(nk[0]);
k = int(nk[1]);
p = input().split(' ');
p = list(map(int,p));

e = [0] *n;
ruiseki = [0]*(n+1);

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

ans = 0;
for i in range(n-(k-1)) :
	if ans < ruiseki[i+k] - ruiseki[i] :
		ans = ruiseki[i+k] - ruiseki[i];

print(ans);

Solution (Python):









n, k = map(int, input().split())
arr = list(map(int, input().split()))
table = {}
ans = 0
for i in range(1, 1000 + 1):
    table[i] = (i + 1) * 0.5
if n == 1:
    print(table[arr[0]])
    exit()
lis = [0 for _ in range(n)]
lis[0] = table[arr[0]]
for i in range(n - 1):
    if i + 1 < k:
        lis[i + 1] = lis[i] + table[arr[i + 1]]
    else:
        lis[i + 1] = lis[i] + table[arr[i + 1]] - table[arr[i - k + 1]]
    ans = max(ans, lis[i + 1])
print(ans)

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


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

Solution (Python):
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])

p_list = list(map(int,input().split()))
  
big = 0
s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + p_list[i]

res = 0
for i in range(N-K+1):
  val = s[K+i] - s[i]
  if res < val:
    res = val

ans = (float(res) / 2) + 0.5 * float(K) 
print(ans)

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


continuous_sum = (lambda n: (n + 1) * (n // 2) + (0 if n %2 == 0 else n // 2 + 1))
calc_expectedval = (lambda p: continuous_sum(p) / p)
expected_vals = [calc_expectedval(int(x)) for x in input().split()]

prevval = sum(expected_vals[0:0+k])
maxval = prevval
for i in range(n - k):
  candidate = prevval - expected_vals[i] + expected_vals[i + k]
  if candidate > maxval:
    maxval = candidate
  prevval = candidate

print(maxval)

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

s = sum([p[i] for i in range(K)])
data = [s]
for i in range(N-K):
    s = s-p[i]+p[i+K]
    data.append(s)
print((max(data)+K)/2)