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

prev = sum(p[1:k])
current = sum(p[1:k])
ind = 0

for i in range(1, n - k + 1):
    current = current - p[i - 1] + p[i + k - 1]

    if prev < current:
        prev = current
        ind = i

total = 0
for i in range(ind, ind + k):
    total += p[i] / 2 + 0.5

print(total)

Solution (Python):
n,k = input().split()
n = int(n)
k = int(k)
nums = [float(i)/2+0.5 for i in input().split()]
ma = sum(nums[0:k])
now = ma
for i in range(n-k):
  now = now - nums[i] + nums[i+k]
  if now>ma:
    ma = now
print(ma)

Solution (Python):
n, k = map(int,input().split())
i = 0
kitaichi = [0] * n
kitaichi_sum = [0] * n
ans = 0
for p in input().split():
  kitaichi[i] = int(p) * (int(p)+1) / 2 / int(p)
  if i == 0:
    kitaichi_sum[i] = kitaichi[i]
  elif i >= k:
    kitaichi_sum[i] = kitaichi_sum[i-1] + kitaichi[i] - kitaichi[i-k]
    if kitaichi_sum[i] > ans:
      ans = kitaichi_sum[i]
  else:
    kitaichi_sum[i] = kitaichi_sum[i-1] + kitaichi[i]
  if kitaichi_sum[i] > ans:
    ans = kitaichi_sum[i]
  i += 1
print(ans)

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

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

ans = (m + k) / 2

print(ans)

Solution (Python):
n,k=map(int,input().split())
li=list(map(int, input().split()))
tmp=0
for i in range(k):
  tmp+=li[i]

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

Solution (Python):
import sys, re
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,copy
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 LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()
    ans = 0
    tmp = 0
    if n == k:
        k = list(accumulate(range(max(p)+1)))
        for x in p:
            ans += k[x]/x
        
        print(ans)
        sys.exit()

    p_ = list(accumulate(p))
    


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

    
    k = list(accumulate(range(max(l)+1)))

    for x in l:
        ans += k[x]/x
        
    print(ans)

if __name__=='__main__':
    main()

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

ans, ai = 0, -1
sum = 0
for i in range(N-K+1):
  if i == 0:
    for k in range(K):
      sum += p[i+k]
  else:
    sum = sum - p[i-1] + p[i+k]
  ans = max(ans, sum)
  if ans == sum:
    ai = i

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

ans = 0.0
for i in range(ai, ai+K):
  ans += dp[p[i]]/p[i]

print(ans)

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

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

s = [0] * (n + 1)
for u in range(1,n + 1):
    s[u] = saikoro[p[u - 1]] / p[u - 1] + s[u - 1]

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

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

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

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

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

max_count = 0
summary = 0
 
for i in range(n-k+1):
    if i == 0:
        summary = sum(p_list[i:i+k])
    else:
        summary += p_list[i+k-1]-p_list[i-1]
    max_count = max(max_count,summary)
 
print(max_count/2 + k/2)

Solution (Python):
import numpy

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

res = numpy.cumsum(q)
ans = []
ans.append(res[k-1])
for i in range(k,n):
  ans.append(res[i]-res[i-k])
print(max(ans))

Solution (Python):

import sys
import numpy as np


def solve(N: int, K: int, p: "List[int]"):
    cumsum = np.cumsum(p)
    
    max_value = 0
    index_first = 0
    for i in range(N - K):
        if max_value < cumsum[i + K] - cumsum[i]:
            max_value = max(max_value, cumsum[i + K] - cumsum[i])
            index_first = i + 1

    
    
    result = 0
    for j in range(K):
        idm = (p[index_first + j] / 2) * (1 + p[index_first + j])
        idm = idm / p[index_first + j]
        result += idm

    print(result)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(N, K, p)


if __name__ == "__main__":
    main()

Solution (Python):
def DE(n):
    return float((float(n)+1)/2)

def main():
    N,K = map(int,input().split())
    p = list(map(DE,input().split()))
    ans = 0
    tmp = [sum(p[:K])]
    for i in range(K,N):
        tmp.append(tmp[i-K]+p[i]-p[i-K])
    print(max(tmp))

if __name__ == '__main__':
    main()

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

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

dp = [0] * (N)
dp_sub = [0] * (N)

dp[0] = (p[0] + 1) / 2
dp_sub[0] = (p[0] + 1) / 2

for i in range(1, K):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i]

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

Solution (Python):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()


memo = [0 for i in range(N - K + 1)]

def solve():
    memo[0] = sum(p[:K])
    for i in range(1, N - K + 1):
        memo[i] = memo[i - 1] + p[i + K - 1] - p[i - 1]
    index = 0
    res = 0
    for i, m in enumerate(memo):
        if res < m:
            res = m
            index = i
    ans = 0
    for i in range(K):
        ans += (p[index + i] + 1) / 2
    return ans
if __name__ == "__main__":
    print(solve())

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

c=0
x=0
m=sum(p[0:k])
z=m
for i in range(1,n-k+1):

  z=z-p[i-1]+p[i+k-1]

  if m<z:
    m=z
    x=i

for i in range(x,x+k):

  c+=((p[i]*(p[i]+1))/2)/p[i]
print(c)

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

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

max = max(P)
dict = {}
sumList = [0] * max

sumList[0] = 1
dict[1] = 1

for i in range(1, max):
    sumList[i] = sumList[i - 1] + (i + 1)
    dict[i+1] = sumList[i] / (i + 1)

for i in range(K):
    li[0] = li[0] + dict.get(P[i])


for i in range(1, N - K + 1):
    li[i] = li[i - 1] - dict.get(P[i - 1]) + dict.get(P[i + K - 1])


print(sorted(li, reverse=True)[0])

Solution (Python):
from collections import deque


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
dices = [int(c) for c in line]

max_E = 0
expectations = deque([0] * K, maxlen=K)
e_memo = {}
E = 0
for dice in dices:
    E -= expectations.popleft()
    if e_memo.get(dice) is None:
        e_memo[dice] = sum(range(1, dice + 1)) / dice
    e = e_memo[dice]
    expectations.append(e)
    E += e
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)

Solution (Python):
def main():
    """"ここに今までのコード"""
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
p=list(map(int,input().split()))
t=0
k=sum(p[0:K])

if N==K:
  print((k+K)/2)
else:
  for i in range(N-K):
    k-=p[i]
    k+=p[i+K]
    if k>t:
      t=k
    
  print((K+t)/2)

if __name__ == '__main__':
    main()

Solution (Python):
N,K = map(int, input().split())
P=input().split()
P = [int(p) for p in P]
maxv=0
expv=0

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

maxv=expv

for i in range(N-K):
    expv=expv-P[i]+P[i+K]
    maxv=max(maxv,expv)
    
        
print("{:.20f}".format((maxv+K)/2))

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

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


wa=sum(P[0:K])
temp=sum(P[0:K])
for i in range(N-K):
    wa+=P[i+K]
    wa-=P[i]
    if temp <= wa:
        temp=wa

ans=s(temp+K-1)
print(ans)

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

Solution (Python):

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

before_pi = p[0]
before_sum = sum(p[0:k])+ 0.0
suml = [sum(p[0:k])]
for i in range(1,n-k+1):
    before_sum = before_sum - before_pi+p[i+k-1]
    suml.append(before_sum)
    before_pi = p[i]


print((max(suml)+k)/2.0)

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

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

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

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

E = []
if K > 1:
    for i in range(N-K+1):
        E.append(S[i+K]-S[i])
    print(max(E))
else:
    print(max(L))

Solution (Python):
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n, k = na()
p = na()
d = [0] * (n + 1)
for i in range(n):
    a = (p[i] * (p[i] + 1) // 2) * (1 / p[i])
    d[i + 1] = d[i] + a

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

print(ans)

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

Solution (Python):
import numpy as np
from scipy.signal import fftconvolve

n, k = map(int, input().split())
P = np.array(input().split(), dtype=int)
template = np.ones(k)

a = fftconvolve(P, template, mode="valid")

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

Solution (Python):
def K(n):
    return 0.5 * (n + 1)

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

    pionta = None
    ire = [None for i in range(k)]
    d = {}
    d[0] = 0

    ss = 0
    for i in range(0, n):
        if k < i + 1:
            pionta = i % k
        if pionta is None:
            ire[i] = p[i]
        else:
            ss += p[i] - ire[pionta]
            d[ss] = i
            ire[pionta] = p[i]


    max_s = max(d.keys())
    i = d[max_s]
    m = 0
    for i2 in range(i-k+1, i+1):
        m += K(p[i2])
    return m
print(d())

Solution (Python):

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

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

expt=list(map(expct,p))

maxval=sum(expt[0:k])
curval = maxval

for i in range(1,n-k+1):
  curval -= expt[i-1]
  curval += expt[k+i-1]

  if curval>maxval:
    maxval=curval

print(maxval)

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

Solution (Python):


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

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

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

print(ans)

Solution (Python):
n, k = [int(i) for i in input().split()]
p = [(int(i) + 1) * 0.5 for i in input().split()]
m = sum(p[:k])
s = m
for i in range(k, n):
    s = s + p[i] - p[i-k]
    m = max(m, s)
print('{:.7f}'.format(m))

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

max_val = 0
max_idx = 0
tmp = 0
for i in range(1,N-K+2):
  if i == 1:
    tmp = sum(p[i-1:i-1+K])
  else:
    tmp = tmp - p[i-2] + p[i-2+K]
  if tmp > max_val:
    max_val = tmp
    max_idx = i

p = p[max_idx-1:max_idx-1+K]
p.sort()
prev_tmp = 0.0
expect = 0.0
for i in range(len(p)):
  tmp = 0.0
  if i == 0:
    for j in range(1,p[i]+1):
      tmp += j
    expect += tmp/p[i]
    prev_tmp = tmp
  else:
    tmp = prev_tmp
    for j in range(p[i-1]+1,p[i]+1):
      tmp += j
    expect += tmp/p[i]
    prev_tmp = tmp
print(expect)

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

s = sum(p[:K]) 
m = s

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

print((m+K)/2)

Solution (Python):



import math
from collections import deque

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

def expected(x):
    s = 0
    if x % 2 == 1:
        s = x * math.ceil(x / 2)
    else:
        s = (x + 1) * (x / 2)

    return s / x

b = {}
mx = 0

q = deque()
p = 0

for i in range(N - K + 1):
    s = 0
    
    if i == 0:
        for j in range(K):
            k = i + j
            if not P[k] in b:
                b[P[k]] = expected(P[k])
            s += b[P[k]]
            
            q.append(b[P[k]])
    else:
        
        k = i + (K - 1)
        if not P[k] in b:
            b[P[k]] = expected(P[k])
        
        f = q.popleft()
        q.append(b[P[k]])

        
        s = p - f + b[P[k]]

    
    mx = max(mx, s)
    
    p = s

print(mx)

Solution (Python):
import numpy as np
import math

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

    def calc(p):
        if p % 2 == 0:
            return p/2 + 0.5
        else:
            return math.ceil(p/2)

    E = [calc(pi) for pi in P]
    

    best_idx = 0
    best_sum = 0

    cs = np.cumsum(E)
    cs = np.insert(cs, 0, 0)
    

    for i in range(K-1, N):
        
        s = cs[i+1] - cs[i-K+1]
        
        if s > best_sum:
            best_sum = s
            best_idx = i

    print(best_sum)

if __name__ == "__main__":
    resolve()

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

q = []
for e in p:
  q.append((e + 1) / 2)

ans = 0
for e in q[0:k]:
  ans += e
anses = [ans]

for i in range(n - k):
  ans -= q[i]
  ans += q[k + i]
  anses.append(ans)

print(max(anses))

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

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    cur = sum(p[0:K])
    max = cur
    for i in range(N - K):
        cur = cur - p[i] + p[i + K]
        if cur > max:
            max = cur

    print((max + K) / 2)


main()

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


kitaiti = {}

k = 1.0
for i in range(1, 1001):
    kitaiti[i] = k
    k += 0.5

index = 0

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

s = index
ans = index

for i in range(1, len(P)-K+1):
    s = index - kitaiti[P[i-1]] + kitaiti[P[i+K-1]]
    if s > ans: ans = s
    index = s
print(ans)

Solution (Python):

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

def cal_expected(p):
    expected = 0
    for i in range(1, p+1):
        expected += i / p
    return expected


expected_dict = {k:cal_expected(k) for k in set(P)}

import copy
from collections import deque

ans_start = 0
dices_sum = 0
tmp_dices = None
for start in range(0, N-K+1):
    if tmp_dices == None:
        tmp_dices = deque(P[start:start+K])
        tmp_sum = sum(tmp_dices)
    else:
        removed = tmp_dices.popleft()
        tmp_dices.append(P[start+K-1])
        tmp_sum = tmp_sum - removed + P[start+K-1]
    if tmp_sum > dices_sum:
        ans_start = start
        dices_sum = tmp_sum



answer = 0
dices = P[ans_start:ans_start+K]
for dice in dices:
    answer += expected_dict[dice]
print(answer)

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

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

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

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

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

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

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])
    now_sum = max_sum
  else:
    now_sum += (p_list[i-1+K] - p_list[i-1])
    if max_sum < now_sum:
      max_sum = now_sum

print((max_sum + K)/2)

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


def cal_expect(value):
    return ((value*(value+1))/2)*(1/value)

expect_value = [0]*N
expect_value[0] = cal_expect(p[0])

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

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

print(max(expect_value))

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

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

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

maxval = 0

temp = -1

def expectedval(inp):
	return (1 + inp) /2

for i in range(n-(k-1)):
	
	summ = 0
	if temp == -1:
		for j in range (k):
			summ += expectedval(plist[i + j])
		temp = summ
	else:
		
		summ = temp - expectedval(plist[i - 1]) + expectedval(plist[i + k - 1])
		temp = summ
	
	maxval = max(summ, maxval)

print(maxval)

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
import queue
import copy


def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z


def bfs(SS, x, y, H, W):
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" 
    for i in range(4): 
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      
      
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" 
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      
  return mlength


def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a


def has_duplicates(seq):
  return len(seq) != len(set(seq))







NK = str(input()).split()
N = int(NK[0])
K = int(NK[1])
p = [int(x) for x in input().split()]

M = 0
ans = 0

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

ans = M
ans2 = 0
ans3 = 0
ans4 = 0

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

for i in range(ans2,ans2+K):
  for j in range(p[i]+1):
    ans3 += j
    
  ans4 += float(ans3/p[i])
  ans3 = 0


print(ans4)

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

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

Solution (Python):
from collections import deque
import itertools
import time

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

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

kukan_max = kukan
for i in range(n - k + 1):
    kukan_max = max(kukan_max, kukan)
    if i+k<n:
        kukan += p[i+k]
        kukan -= p[i]
ans = kukan_max / 2 + 0.5 * k
print(ans)

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

Solution (Python):
from itertools import accumulate

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

st = list(accumulate(range(1001)))

table = [0] * (n + 1)
for i in range(1, len(table)):
    table[i] = table[i-1] + (st[p[i-1]] / p[i-1])
    
    
ans = table[k]
for i in range(k+1, len(table)):
    ans = max(ans, table[i] - table[i-k])

print(ans)

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

for i in range(len(p)):
    p[i]=(p[i]+1)/2
tmp=sum(p[0:k])
x=sum(p[0:k])
for i in range(k,len(p)):
    x=x-p[i-k]+p[i]
    if x>tmp:
        tmp=x
print(tmp)

Solution (Python):

import numpy as np

n, k = map(int, input().split())
p = np.array(input().split(), dtype='int')

max_E = 0

e = (p - 1) * 0.5 + 1

first_E = 0
for i in range(k):
    first_E += e[i]

for i in range(n - k + 1):
    if i == 0:
        E = first_E
    else:
        E = E - e[i - 1] + e[i + k - 1]
    
    if E > max_E:
        max_E = E

print(max_E)

Solution (Python):

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


s = sum(p[0:K])
s_max = s

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

    if s_max < s:
        s_max = s

print((s_max+K)/2)

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


sum_list = [0 for _ in range(300000)]
sum = 0

for i in range(len(p)):
    sum += p[i]
    sum_list[i] = sum


mev = 0
idx = 0
for i in range(N-K+1):
    ev = sum_list[i+K]-sum_list[i]
    if ev > mev:
        idx = i
        mev = ev

mev = 0.0
if N != K:
    for i in range(idx+1,idx+1+K):
        mev += (p[i] + 1.0) / 2.0

else:
    for i in range(len(p)):
        mev += (p[i] + 1.0) / 2.0

print(mev)

Solution (Python):
def solve():
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))
    curSum = sum(ps[:K])
    curMax = curSum
    i = K; j = 0
    while i < N:
        curSum -= ps[j]
        curSum += ps[i]
        curMax = max(curSum, curMax)
        i += 1; j += 1
    print((curMax + K) / 2)
solve()

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

number_list = []

sum_max = 0
tmp_max = 0
past_max = 0
tmp_max_list = []
for index, p in enumerate(p_list):
    if index >= K:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max -= tmp_max_list[index - K]
        if sum_max < tmp_max:
            sum_max = tmp_max
        tmp_max_list.append((p * (p + 1)) / 2 / p)
    else:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max_list.append((p * (p + 1)) / 2 / p)

if N == 1:
    print('{:.12f}'.format(float(p_list[0] * (p_list[0] + 1) / 2 / p_list[0])))
elif N == K:
    print('{:.12f}'.format(float(sum(tmp_max_list))))
else:
    print('{:.12f}'.format(float(sum_max)))

Solution (Python):
t = input().split(" ")

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

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

ans = 0
a =0

for i in range(len(p)):
    
    
    p[i] = ((p[i]*(p[i]+1))/2)/p[i]
    a += p[i]
    
    if i >= K-1:
        
        if i >= K:
            a += -(p[i-K])
        if a > ans:
            ans = a

print(ans)

Solution (Python):


n, k = map(int, input().split())
P = [int(i) for i in input().split()]

if k == 1:
    m = max(P)
    print((m+1)/2)

else:
    Pa = [(1+h)/2 for h in P]
    if n == k:
        print(sum(Pa))
    else:
        sm = sum(Pa[:k])
        r_ind = k-1
        r_res = k-1
        l_ind = 0
        l_res = 0
        s = sm
        while r_ind < n - 1:
            right = Pa[r_ind + 1]
            left = Pa[l_ind]
            s += right
            s -= left
            if sm < s:
                sm = s
                l_res = l_ind
                r_res = r_ind
            r_ind += 1
            l_ind += 1

        m = 0
        for f in Pa[l_res+1:r_res+2]:
            m += f

        print(m)

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

def calc_exp(n):
    exp=1+(n-1)*0.5
    return exp

tmp=sum(p[:k])
mx=tmp
ind=0
for i in range(1,n-k+1):
    
    tmp-=p[i-1]
    tmp+=p[i+k-1]
    if mx<tmp:
        ind=i
        mx=tmp
        
ans=0
for i in range(k):
    ans+=1+(p[ind+i]-1)*0.5
    
print(ans)

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

p = list(map(int,input().split()))
max = 0
for i in range(K):
    max += (1+p[i])/2
tmp = max
for i in range(K,len(p)):
    tmp -= (1+p[i-K])/2
    tmp += (1+p[i])/2
    
    if max < tmp:
        max = tmp
    
print(max)

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

ans = 0
tmp,ind = sum(p[0:k]),0
sumn = tmp

for i in range(len(p)-k):
    
    tmp += p[i+k]-p[i]
    
    if tmp >= sumn:
        ind,sumn = i,tmp
        

print((sumn+k)/2)
"""
for i in p[ind:ind+k]:
    ans += (i+1)/2
else:
    print(ans)
"""

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

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

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

pp = list(map(lambda x: mysum[x] / x, p))

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

Solution (Python):
n, k = map(int,input().split())
arr = list(map(int, input().split()))
kitai = 0
biglist = []
if k ==1:
    kitai = (max(arr)+1)/2
    print(kitai)
else:
    for i in range(n-k+1):
        if i == 0:
            big = 0
            for j in range(i+k):
                big = big + arr[j]
        else:
            big = biglist[i-1] - arr[i-1] + arr[i+k-1]
        biglist.append(big)
    max_value = max(biglist)
    max_index = biglist.index(max_value)
    for j in range(max_index,max_index+k):
        kitai = kitai + (arr[j]+1)/2
    print(kitai)

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

def exp(n):
    if n % 2 == 0:
        s = (n+1)*n/2
    else:
        s = (n+1)*(n-1)/2+(n+1)/2
    ans = s / n
    return ans

q = []
for i in range(N):
    q.append(exp(p[i]))


S = sum([q[i] for i in range(K)])
M = S


for i in range(N-K):
    S = S - q[i] + q[K+i]
    
    if S > M:
        M = S

print('{:.12f}'.format(M))

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

Solution (Python):








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

max_index = 0
now_sum = sum(P[:K])
max_sum = now_sum
for i in range(1, len(P)-(K-1)):
    now_sum -= P[i-1]
    now_sum += P[i+K-1]
    
    if now_sum > max_sum:
        max_sum = now_sum
        max_index = i





kk = P[max_index:max_index+K]


max_kk = max(kk)
dp = [0]
for i in range(1, max_kk+1):
    dp.append(dp[i-1] + i)


ans = 0
for k in kk:
    ans += dp[k]/k

print(ans)

Solution (Python):
def mysum(n):
    ans = 0
    for i in range(1,n + 1): 
        ans += i  / n
    return ans

n,k = map(int,input().split())
p = list(map(int,input().split()))
a2=[0]
Max = 0
for i in p:a2.append(a2[-1]+i)
lists = []
for i in range(n-k+1):
    lists.append(a2[i+k] - a2[i])
jud = max(lists)
for i in range(len(lists)):
    if lists[i] == jud:
        tmp = i
ans = p[tmp:tmp+k]
cnt = 0
for i in ans:
    cnt += mysum(i)
print(cnt)

Solution (Python):
[N,K] = [int(s) for s in input().rstrip().split(' ')]
L_A = [int(s) for s in input().rstrip().split(' ')]
if N < K:
  print("error")
elif N == K:
  print((sum(L_A) + N) / 2)
else:
  a = N - K
  p = 0
  for i in range(K):
    p += L_A[i]
  q = p
  for j in range(N-K):
    q += L_A[j+K]-L_A[j]
    p = max(p,q)
  print((p + K) / 2)

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


t = [0] * (len(p) + 1)
for i in range(len(p)):
  t[i + 1] = t[i] + p[i]


maximum = -1
start = -1

for i in range(len(p) - k + 1):
  temp = t[i + k] - t[i]
  if temp > maximum:
    maximum = temp
    start = i


exp = 0
for i in range(start, start + k):
  temp = 1 / 2 * p[i] * (p[i] + 1)
  exp += temp / p[i]

print(exp)

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



def max_cal(max_p,sum_p):
    if(max_p < sum_p):
        max_p = sum_p
    return max_p

if __name__ == '__main__':
    max_p = 0
    sum_p = 0
    for k in range(K):
        sum_p = sum_p + p[k]
        max_p = max_cal(max_p, sum_p)
    
    for j in range(1,N-K+1):
        sum_p = sum_p - p[j-1] + p[j+K-1]
        max_p = max_cal(max_p, sum_p)
    
    print((max_p+K)/2)