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):
from copy import copy
N, K = map(int, input().split())

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

now_sum = sum(p[0:K])
now_max = copy(now_sum)


for i in range(K,N):
    now_sum = now_sum - p[i - K] + p[i]
    if now_sum > now_max:
        now_max = copy(now_sum)

print((K + now_max)/2)

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

maxSum = 0
sum = 0
prevSum = 0

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

prevSum = maxSum;
for i in range(N - K):
  sum = prevSum - p[i] + p [i + K]
  if maxSum < sum:
    maxSum = sum
  prevSum = sum

ans = (maxSum + K) / 2.0
print('{:.7f}'.format(ans))

Solution (Python):
n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

ans = 0
cur = 0
for i in xrange(k):
  cur += a[i]

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

ans = ans + k
ans /= 2.0

print "{0:.9f}".format(ans)

Solution (Python):
arr = input().split(" ")
N = int(arr[0])
K = int(arr[1])

input_arr = input().split(" ")
arr = []


max = 0
tmp = 0
if(K > 1):
    for i in range(N):
        pi = int(input_arr[i])
        ex = (1+pi)/2
        arr.append(ex)
        tmp += ex
        if(i >= K-1):
            if(max <= tmp):
                max = tmp
            tmp -= arr[i-K+1]
else:
    for i in range(N):
        pi = int(input_arr[i])
        ex = (1+pi)/2
        if(ex > max):
            max = ex
print(max)

Solution (Python):
import numpy as np
n,k = map(int,input().split())

p = np.array(input().split(),np.int)


fs = p[:k]
f = sum(fs)
m = n - k + 1
qs = np.zeros(m)
qs[0] = f
if n == k:
    ans = (f + k)/2
    print(ans)
else:
    for i in range(k,n):
        a = qs[i-k] - p[i-k] + p[i]
        qs[i-k+1] = a
    ans = (max(qs)+k) / 2
    print(ans)

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

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

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

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

print(kitaiti(ans)+0.5*(K-1))

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

n, k = [int(i) for i in input().split()]
p = [0] * n
for i,v in enumerate(input().split()):
    p[i] = 1.0 + 0.5 * (float(v) - 1.0)

_max_sum = 0
_prev_sum = 0
for i in range(0, n-k+1):
    if i == 0:
        _sum = sum(p[:k])
    else:
        _sum = _prev_sum - p[i-1] + p[i+k-1]
    if _sum >= _max_sum:
        _max_sum = _sum
    _prev_sum = _sum
print(_max_sum)

Solution (Python):
N, K = map(int,input().split())
P = list(map(int,input().split()))
LIST = [0]
for i in range(N):
    LIST.append(LIST[i]+P[i])
MAX = 0
for i in range(N-K+1):
    tmp = LIST[i+K]-LIST[i]
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)

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

rp = sum(list(p[0:K]))
rm = 0
ans = rp
for i in range(N-K):
  rp += p[i+K]
  rm += p[i]
  if rp - rm > ans:
    ans = rp - rm

print((ans+K)/2)

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

kitaiti = [0 for _ in range(n)]
ruisekiwa = [0 for _ in range(n)]
r = k - 1
max = 0
now = 0
ans_list = []

for i in range(n):
    kitaiti[i] = (p[i]+1) / 2
    if i == 0:
        ruisekiwa[0] = kitaiti[0]
    else:
        ruisekiwa[i] = ruisekiwa[i-1] + kitaiti[i]
    if i == r:
        now = ruisekiwa[i]
    elif i > r:
        now = ruisekiwa[i] - ruisekiwa[i-r-1]
    if now > max:
        max = now
print(max)

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

a = []
for e in p:
    a.append((1+e)/2.0)

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

res = []
res.append(tmp)
for i in range(k,n):
    tmp += a[i] - a[i-k]
    res.append(tmp)

print(max(res))

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

ls = []
ans = 0

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

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

ans = 0
for i in range(k):
    pp = p[max_index+i]
    for j in range(pp):
        ans += (1/pp*(j+1))
    
print(ans)

Solution (Python):
N, K = map(int, input().split())
p = list(map(int, input().split()))
fac = [0] * 735477
fac[0] = 1
if (N >= 1):
    for i in range(1, 1010): fac[i] = i + 1 + fac[i - 1]


exp = [0] * 735477
for i in range(N):
    exp[i] = fac[p[i] - 1] / p[i]


Ans = 0
ans = [0] * 735477
ans[0] = sum(exp[:K])
for i in range(1, N - K + 1):
    if(i + K == N + 1): break
    ans[i] = ans[i - 1] - exp[i - 1] + exp[i + K - 1]
    
    
print(max(ans))

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

if K==1:
    print((max(p)+1)/2)
    exit()

contents_origin=sum(p[:K])
contents=sum(p[:K])
pK = p[:K]

for idx, i in enumerate(p[:-K]):
    contents=contents-p[idx]+p[idx+K]
    contents_origin=max(contents_origin,contents)
print((contents_origin+K)/2)

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

loop_time = N - K

l_s = 0
l_e = K
max_score = 0
test_score = 0

ans_list = p_list[l_s:l_e]
for j in ans_list:
    max_score += sum(range(1,j+1)) / j
    test_score = max_score
l_s = l_s + 1

for i in range(loop_time):
    
    pop_e = p_list[l_s-1]
    test_score = test_score - sum(range(1,pop_e+1)) / pop_e
    
    push_e = p_list[l_e]
    test_score = test_score + sum(range(1,push_e+1)) / push_e
    if test_score > max_score:
        max_score = test_score
    l_s = l_s + 1
    l_e = l_e + 1

print(max_score)

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

sum = 0
for k in range(K):
  sum += p_list[k]
max = sum

i = 0
while(i + K  < N):
  sum = sum - p_list[i] + p_list[i+K]
  if(sum > max):
    max = sum
  i += 1

print(0.5 * (max+K))

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

mini = 0
kitai = 0
sum1 = []
p2 = []
ans = 0
base = 0
sei = 0
a = 0
d = {}
for i in range(max(p) + 1):
    a += i + 1
    sum1.append(a)

for i in range(k):
    p3 = sum1[p[i] - 1] / (p[i])
    p2.append(p3)
    base += p3


ans = base


for i in range(1, n):
    if i + k - 1 >= n:
        break
    else:
        p3 = sum1[p[i + k - 1] - 1] / (p[i + k - 1])
        p2.append(p3)
        base = base - p2[i - 1] + p3
        if ans < base:
            ans = base

print(ans)

Solution (Python):


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

def main():
    n, k = map(int, input().split())
    fp = [f(int(i)) for i in input().split()]
    n = len(fp)
    v = sum(fp[0:k])
    i = 0
    ans = v
    while i+k <= n-1:
        v = v-fp[i]+fp[i+k] 
        ans = max(ans, v)
        i+=1

    a = "{0:.12f}".format(ans)
    print(a)

main()

Solution (Python):
from collections import deque

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


d = deque()
vmax = 0
v = 0
for p in ps:

    if len(d) == k:
        old = d.popleft()
        new = p
        d.append(new)
        v = v + new - old
        if v > vmax:
            
            vmax = v
    else:
        d.append(p)
        v += p
        vmax = v
    

print(vmax)

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

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

import numpy as np

Ps = np.array(Ps)

Exp_each_p = (Ps + 1) /2

sum_Exp = [sum(Exp_each_p[0:k])]
if n == 1:
    print(sum_Exp[0])
else:    
    for id in range(1, n - k + 1):
        sum_Exp.append(sum_Exp[id - 1] - Exp_each_p[id - 1] + Exp_each_p[id + k - 1])

    print(max(sum_Exp))

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

maxstart = 0
maxval = 0
nowval = 0
for i in range(K):
  nowval += p[i]
maxval = nowval
  
for i in range(N-K):
  nowval -= p[i]
  nowval += p[i+K]
  if nowval > maxval:
    maxval = nowval
    maxstart = i+1

ans = 0
for i in range(K):
  ans += (p[i+maxstart] + 1)

print(ans/2)

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

if (K == 1):
    answer = (max(P) + 1) / 2
    print(answer)
    exit()

total = sum(P[0: 0 + K])
max_index = 0
P_sum = []
P_sum.append(total)

for i in range(K, len(P)):
    change = P[i] - P[i - K]
    tmp = change + P_sum[-1]
    
    P_sum.append(tmp)

maxx = max(P_sum)
answer = (maxx + K) / 2
print(answer)

Solution (Python):
str_N = input().split()
N = int(str_N[0])
K = int(str_N[1])
str_p = input().split()
p = [float(str_p[i]) for i in range(N)]

ans = 0
e_sum = 0

for j in range(K):
  e_sum = e_sum + (p[j]+1)/2

ans = e_sum
for i in range(K,N):
  e_sum = e_sum + (p[i]+1)/2
  e_sum = e_sum - (p[i-K]+1)/2
  if ans<e_sum:
    ans=e_sum

print(ans)

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

ansl = 0
ansr = k-1
ans = 0
tmp = sum(p[:k])

for i in range(1,n - k+1):
    tmp = tmp - p[i-1] + p[i + k-1]
    
    if tmp > ans:
        ansl = i
        ansr = i + k - 1
        ans = tmp

ans2 = 0
for i in range(ansl, ansr + 1):
    ans2 += (p[i] + 1) / 2
print(ans2)

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

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

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


s = 0
for j in range(K):
    s += p[j]

sm = s

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

print( sm/2+0.5*K)

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

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

p = list(map(int,input().split()))
counter_li = []
first = 0
for i in range(k):
    first+=p[i]
counter_li.append(first)
for i in range(1,len(p)-k+1):
    counter_li.append(counter_li[i-1]+ p[i+k-1] - p[i-1])
print(max(counter_li)/2+k/2)

Solution (Python):
from itertools import accumulate
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
A = (A+1)/2

B = np.insert(A,0,0)
B = list(accumulate(B))
answer = []
for i in range(N-K+1):
    answer.append(B[i+K]-B[i])

print(max(answer))

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

pmax=sum(pi[0:k])

psum=pmax
for i in range(1,n-k+1):
    psum=psum-pi[i-1]+pi[i+k-1]

    if psum>pmax:
        pmax=psum
px=(k+pmax)/2
print(px)

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

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

print(max(a))

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

Solution (Python):
n, k = map(int, input().split())
p_i = list(map(int,input().split()))
answer = 0
sum = 0
for x in range(n):
    if x <= k - 1: 
        sum += p_i[x]
        if x == k - 1: answer = sum
    else:
        sum += p_i[x] - p_i[x - k]
        answer = max(answer, sum)
print((answer + k) / 2)

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

exp = [(x+1)*0.5 for x in p]

sums = []
sums.append(0.0)
for i in range(1,N+1):
    sums.append(sums[i-1]+exp[i-1])


ans = 0.0
for i in range(N-K+1):
    if ans < sums[i+K] - sums[i]: ans = sums[i+K] - sums[i];

print(ans)

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

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

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

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

print(ans)

Solution (Python):
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

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


sum_EV = 0
for i in range(K):
  sum_EV = sum_EV + EV_p_list[i]


max_EV = sum_EV
for i in range(1, N - K + 1):
  sum_EV = sum_EV - EV_p_list[i - 1] + EV_p_list[i + K - 1]
  if sum_EV > max_EV:
    max_EV = sum_EV

print(max_EV)

Solution (Python):
def calc_E(prob):

    E = (prob + 1) / 2
    return E

def main(N, K, list_p):
    
    list_E = list(map(calc_E, list_p))
    max_E  = sum(list_E[0:K])
    prev_E = sum(list_E[0:K])

    for i in range(1, N-K+1):
        tmpE   = prev_E - list_E[i-1] + list_E[i-1+K]
        max_E  = max(max_E, tmpE)
        prev_E = tmpE

    return max_E
        


if __name__ == "__main__":

    [N, K] = list(map(int, input().split(' ')))
    list_p = list(map(int, input().split(' ')))

    answer = main(N, K, list_p)
    print(answer)

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

firstValue =  (r[0] / 2) + 0.5


firstSet = r[0:k]
tempMax = 0
for p in firstSet:
    tempMax += (p / 2) + 0.5

maxSum = tempMax
beforeSum = tempMax

for i in range(k,n):
    lastValue = (r[i] /2)+0.5
    nowValue = beforeSum - firstValue + lastValue
    if nowValue > maxSum:
        maxSum = nowValue

    beforeSum = nowValue
    firstValue = (r[i-k+1]/2)+0.5

print(maxSum)

Solution (Python):
import numpy
a,b = map(int,input().split())
li = list(map(int,input().split()))
L = [(i**2+i)/(2*i) for i in li]
dp=[0]*a
res = numpy.cumsum(L)
dp[0] = res[b-1]
for i in range(1,a-b+1):
    dp[i] = res[i+b-1]-res[i-1]
print(max(dp))

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

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

max_num = 0
l = 0
m = 0
for i in range(N):
    if K+i > N:
        break
    tmp = S[K+i]-S[i]
    if tmp > max_num :
        l = K+i
        m = i
        max_num = tmp

S = P[m:l]
ans = 0
for i in range(len(S)):
    gausu = (S[i])*(S[i]+1)/2
    ans += (gausu/S[i])

print(ans)

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

kitai = [None]*(1001)
for i in range(1, 1001):
    kitai[i] = (0.5*i*(i+1))/i

ruiseki = P.copy()
ruiseki[K-1] = sum(ruiseki[0:K])
for i in range(K, N):
    ruiseki[i] = ruiseki[i-1]+P[i]-P[i-K]

ind = np.array(ruiseki).argmax()
temp = P[ind-K+1:ind+1]
ans = 0
for t in temp:
    ans+=kitai[t]
print(ans)

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

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

max_num = 0
l = 0
m = 0
for i in range(N):
    if K+i > N:
        break
    tmp = S[K+i]-S[i]
    if tmp > max_num :
        l = K+i
        m = i
        max_num = tmp

S = P[m:l]
ans = 0
for i in range(len(S)):
    gausu = (S[i])*(S[i]+1)/2
    ans += (gausu/S[i])

print(ans)

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

dp = [0] * n
m = {}

def func(x):
    return m.get(x, sum(range(x+1)) / x)
    

for i in range(n):
    if i - k >= 0:
        dp[i] = dp[i - 1] - func(P[i - k]) + func(P[i])
    else:
        dp[i] += func(P[i]) + dp[i-1]

print(max(dp))

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

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

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

tmp_sum = sum(p[0:k])
ans = (tmp_sum + k) / 2
count = float(0)
for i in range(k, n):
    tmp_sum = tmp_sum + p[i] - p[i - k]
    tmp = (tmp_sum + k) / 2
    if ans <= tmp:
        ans = tmp

print(ans)

Solution (Python):
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)

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


j = n-k
s = p[0:k]
max = sum(s)
su = max

for i in range(j):
    t = su+p[i+k]
    u = t-p[i]
    if max < u:
        max = t-p[i]
        s = p[i+1:i+1+k]

    su = u

def summ(i):
    return i*(i+1)/2

ss = 0


for i in s:
    ss += summ(i)/i

print(ss)

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

sum_max = sum(p[0:k])
sum_temp = sum_max

for i in range(n-k):
     sum_temp = sum_temp - p[i] + p[i+k]
     if sum_temp > sum_max:
         sum_max = sum_temp

s_max = (sum_max + k) / 2

print(s_max)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    from itertools import accumulate

    def e(dice):
        ans = 0
        for r in range(1, dice+1):
            ans += r /dice
        return ans

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

    p_cum = [0] + list(accumulate(p))

    ma = 0
    ind = 0
    for i in range(k, n+1):
        temp = p_cum[i] - p_cum[i-k]
        if ma < temp:
            ma = temp
            ind = i

    x = p[ind-k:ind]

    print(sum(e(d) for d in x))

if __name__ == '__main__':
    main()

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

n, k = map(int, input().split())
l = list(map(int, input().split()))
ex = []
exsum = [0] *300000

tmpmax = 0
for i in range(n):
  ex.append(E(l[i]))

for i in range(n-k+1):
  if i == 0:
    for j in range(k):
      tmpmax += ex[i+j]
      exsum[i] = tmpmax
  else:
    exsum[i] = exsum[i-1] - ex[i-1] + ex[i+k-1]
  
a = exsum.index(max(exsum))

print(exsum[a])

Solution (Python):


n, k= [0] * 2
p = []

def format_input(filename = None):
	global n, k
	global p
	if filename == None:
		n, k = list(map(int, input().split()))
		p = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 2 * 10**5)
		k = rng(1, n)
		p = [rng(1, 10**3) for i in range(n)]

def get_answer():
	e = []
	e.append(sum(p[0:k]))
	for i in range(n - k):
		e.append(e[i]-p[i]+p[i+k])
	e.sort()
	answer = float(e.pop() + k) / 2.0
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

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

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

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

Solution (Python):

ex = []
for i in range(1001):
    e = 0
    j = i 
    while j != 0:
        e += j / i
        j-=1
    ex.append(e)

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

total = 0
mx = 0

for i in range(n):
    if i < k:
        total += ex[p[i]]
    else:
        total = total + ex[p[i]] - ex[p[i-k]]
    if mx < total:
        mx = total

print(mx)

Solution (Python):


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

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

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

sum=max
for i in range(1, n-k+1):
    sum=sum-q[i-1]+q[i+k-1]
    if sum > max:
        max=sum
print(max)

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

X = list(accumulate([0] + X))
mm = 0
for i in range(N-K+1):
    mm = max(mm, X[i+K] - X[i])
print(mm)

Solution (Python):
A = [int(a) for a in input().split()]
N = A[0]
K = A[1]

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

raw_max = sum(P[0:K])
maxnum = 0
sum_tmp = sum(P[0:K])

for i in range(1, N-K+1):
    sum_tmp = sum_tmp - P[i-1] + P[i+K-1]
    if(raw_max < sum_tmp):
        raw_max = sum_tmp
        maxnum = i

ev_max = [(n+1)/2 for n in P[maxnum:maxnum+K]]

print(sum(ev_max))

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

d = []
d.append(sum(p[:k]))

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

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

Solution (Python):
N, K=map(int, input().split())
Pn=list(map(int, input().split()))
V = [0] * N
ans = [0] * K
max_v = 0
sum_v = 0
for n in range(N):
    V[n] = (0.5*Pn[n]*(Pn[n]+1))/Pn[n]
    if n < K:
        sum_v += V[n]
        max_v = sum_v
    else:
        sum_v = sum_v - V[n-K] + V[n]
        max_v = max(max_v, sum_v)
print(max_v)

Solution (Python):
def main():
    N,K = map(int, input().split())
    pi = list(map(int, input().split()))
    max_num = 0
    new_pi = [0] * N
    sum_new_pi = [0] * (N+1)

    for i in range(N):
        new_pi[i] += (1+pi[i])/2

    for i in range(N):
        sum_new_pi[i+1] = sum_new_pi[i] + new_pi[i]

    for i in range(N):
        if i+K > N:
            break
        s = sum_new_pi[i+K] - sum_new_pi[i]
        if s > max_num:
            max_num = s

    print(max_num)

if __name__ == "__main__":
    main()

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

A=[]
base=0
B=[]

for i in range(N):
    if p[i]%2==0:
        A.append(((p[i]+1)*p[i]//2)/p[i])
    else:
        A.append((((p[i]+1)*(p[i]//2)+((p[i]+1)//2)))/p[i])
    
for l in range(K):
    base+=A[l]
B.append(base)
for k in range(K,N):
    base+=A[k]
    base-=A[k-K]
    B.append(base)    

print(max(B))

Solution (Python):
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ruiseki = []
a = 0
for i in range(n):
  a += p_list[i]
  ruiseki.append(a)
res = -1
val_list = []
for m in range(n-k):
  val = ruiseki[k+m] - ruiseki[m]
  val_list.append(val)
if n ==k :
  	print((sum(p_list) + k)/2)
else:
	print((max(val_list)+k)/ 2)

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

psum = []
pini = sum(p[:K])
psum.append(pini)
for i in range(1, N-K+1):
    pini = pini - p[i-1] + p[i+K-1]
    psum.append(pini)
print((max(psum)+K)/2)

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

Solution (Python):
import numpy
N, K = map(int, input().split())
p = numpy.array(list(map(int, input().split())))
max = 0
nowsum = 0
for i in range(N-K+1):
    if i == 0:
        nowsum = numpy.sum(p[i:i+K])
    else:
        nowsum = nowsum - p[i-1] + p[i+K-1]
    if max < nowsum:
        max = nowsum
        maxno = i

exsum = 0

for i in range(K):
    temp = p[i+maxno]
    exsum += (0.5*temp*(temp+1))/temp
print(exsum)

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

e = []

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

ans = sum(e[0:k])
s = ans

for i in range(k,n):
  aaa = s + e[i] - e[i-k]
  if ans < aaa:
    ans = aaa
  s = aaa
print(ans)

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

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

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

print((total_max + k) / 2)

Solution (Python):

N , K = map( int , input().strip().split(" ") ) ; 
LL = [] ;
for x in input().strip().split(" " ) :
	k = int(x ) ;
	LL.append(  ( k * ( k + 1 ) ) / k / 2 ) ;

LL2 = [] ;
LL2.append( LL[0] ) ;
for x in range ( 1 , len( LL ) ) :
	LL2.append( LL2[-1] + LL[x] ) ;



v0 = 0 ;
for x in range ( K-1 , N  ) : 
	d = 0. if x - K < 0 else LL2[x-K];
	v = LL2[x] -d ;
	v0 = max ( v , v0 ) ;
print ( "{0:.8f}".format(  v0 ) ) ;

Solution (Python):
n, k = map(int, input().split())
p = list(map(int, input().split()))
nums = []
elm = 0
for num in p:
    elm += (num * (num + 1) / 2) * (1 / num)
    nums.append(elm)
maxVal = nums[k-1]
for i in range(n - k):
    if nums[i + k] - nums[i] >= maxVal:
        maxVal = nums[i + k] - nums[i]
    else:
        continue
print(maxVal)

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.int32)
Pcum[1:] = P.cumsum()

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

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math

import itertools



import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default






def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    temp=0
    max=sum(p[0:k])
    maxi=0
    temp=max
    if n>=2:
        for i in range(1,n-k+1):
            temp-=p[i-1]
            temp+=p[i+k-1]
            if temp>max:
                max=temp
                maxi=i
    total=(max+k)/2

 

    print(total)

if __name__ == "__main__":
    main()

Solution (Python):

def Main(N, K, P):
    wa = sum(P[:K])
    max_sum = wa
    max_sum_ind = 0
    for i in range(N-K):
        wa = wa - P[i] + P[i+K]
        if(wa > max_sum):
            max_sum = wa
            max_sum_ind = i
    ans = 0
    if max_sum_ind == 0:
        for i in range(K):
            ans += (P[i]+1)/2
    else:
        for i in range(max_sum_ind+1, max_sum_ind+K+1):
            ans += (P[i]+1)/2
    return ans

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    print("{:.12f}".format(Main(N, K, P)))

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, k  = MAP()
p = LIST()

def kitai(a):
    tmp = 0
    
    tmp = 1/a * (1/2 * a * (a+1))
    return tmp
    
ans = 0
max_index = 0


max_ruiseki = sum(p[0:k])
now_ruiseki = 0
ruiseki = [max_ruiseki]
for left in range(n-k+1):
    if left != 0:
        right = k + left 
        
        
        
        new_ruiseki = ruiseki[left-1] + p[right-1] - p[left-1]
        ruiseki.append(new_ruiseki)


m = 0
max_index = 0
for i in range(len(ruiseki)):
    if m != max(m, ruiseki[i]):
        m = ruiseki[i]
        index = i



A = p[index:index+k]
    
for a in A:
    ans += kitai(a)
print(ans)

Solution (Python):

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

p_shift = p[k:] + [0] * k

con_p = [0] * dices
sum_first_k = sum(p[0:k])

con_p[0] = sum_first_k

for i in range(dices-k):
    con_p[i+1] = con_p[i] + p_shift[i] - p[i]

max_expectation = (k + max(con_p))/2.
print(max_expectation)

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

Solution (Python):
from itertools import accumulate

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

ac = [0] + list(accumulate(map(lambda x: (1 + x) / 2, p)))
ans = max(ac[i+k] - ac[i] for i in range(n - k + 1))
print(ans)

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

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



max = -1
if n == k:
    max = P_ave_sum[n - 1]
else:
    for j in range(n - k):
        sum_k = P_ave_sum[j + k] - P_ave_sum[j]
        if sum_k > max:
            max = sum_k

print(max)

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

Solution (Python):
def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

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

m = []
for i in range(n):
    a = gauss(p[i]) / p[i]
    m.append(a)

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

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