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 math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def ifn(): return float(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def fmn(): return map(float, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, input().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD

N,K = imn()
p = iln()

ans = 0
total = 0
c = [0 for _ in range(N+1)]
for i in range(N):
    c[i] = ((p[i] * (p[i] + 1)) // 2 / p[i])
    total += c[i]
    if i+1 >= K:
        ans = max(ans, total)
        total -= c[i-K+1]
print(ans)

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

max_s = sum(p[0:K])
s = sum(p[0:K])
for i in range(N-K):
    f = p[K+i]
    b = p[i]
    ns = s + f - b
    if ns >= max_s:
        max_s = ns
    s = ns
    

print((K+max_s)/2)

Solution (Python):
x = list(map(int, input().split()))
y = list(map(int, input().split()))
y = [i/2+0.5 for i in y]
max_value = 0
value = sum(y[:x[1]])
for i in range(x[1], x[0]):
  max_value = max(max_value, value)
  value += y[i]
  value -= y[i-x[1]]
max_value = max(max_value, value)
print(max_value)

Solution (Python):

from collections import deque

def main():
    N, K = map(int, input().split())
    ps = map(int, input().split())

    dq = deque()
    maxnum = None
    total = None

    for idx, p in enumerate(ps):
        dq.append(p)

        if len(dq) == K:
            total = sum(dq)
            maxnum = total

        if len(dq) > K:
            popnum = dq.popleft()
            total -= popnum
            total += dq[-1]
            if total > maxnum:
                maxnum = total

    exp = (maxnum + K) / 2.0
    print(exp)


if __name__ == '__main__':
    main()

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


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

def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

c = cumsum(k)
c = [0] + c
ans = 0

for i in range(N-K+1):
    t = c[i+K] - c[i]

    if t > ans:
        ans = t

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n):
    a=p[i]
    p[i]=a*(a+1)//2/a

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

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

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

pi={}
pi[0]=0
pi[1]=1
for i in range(2,1002):
    pi[i]=pi[i-1]+i
    pi[i-1]=pi[i-1]/(i-1)

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




result=temp

for i in range(k,n):
    temp=temp-pi[p[i-k]]+pi[p[i]]
    
    result=max(result,temp)
print(result)

Solution (Python):


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

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

for i, p in enumerate(P[K:]):
    s = s + p - P[i]
    m = max(m, s)


print('{:.9f}'.format((m+K)/2))

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
total = 0
saidai = -9999
ans = 0
B = [0]*(len(A)+1)
for i in range(len(A)):
    total += A[i]
    B[i+1] = total
for j in range(N-K+1):
     if B[j+K]-B[j]>saidai:
            saidai = B[j+K]-B[j]
            P = A[j:j+K]
for i in range(len(P)):
    ans += (0.5*P[i]*(P[i]+1))/P[i]
print(ans)

Solution (Python):
import sys
import math
from itertools import accumulate
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,K=LI()
acc = LI()
for i in range(N):
    acc[i] = (1+acc[i]) / 2
acc2 = list(accumulate(acc))



res = acc2[N-1] if K == N else 0
for i in range(1, N-K+1):
    if i == 1:
        res = acc2[K-1]
    else:
        res = max(res, acc2[i+K-1] - acc2[i-1])
    

print(res)

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

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

sum_p_max = sum(p[0:K])
sum_i = sum(p[0:K])

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

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

dat2 = []
m = -1

n = sum(dat[:k])
dat2.append(n)
m = n
mind = 0
for i in range(1, len(dat) - k ):
    
    
    
    n += dat[k+i]
    n -= dat[i]
    dat2.append(n)
    if n > m:
        m = n
        mind = i + 1






r = 0
for i in range(mind, mind + k):

    r += (dat[i] + 1) / 2

print(r)

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

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

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

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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

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

cnt = 0
dice = [(i+1)/2 for i in p]

ans = sum(dice[:k])
exp = sum(dice[:k])

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

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

print(max(D) / 2 + 0.5 * K)

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

e = [0 for i in range(n)]
_e = 0

for i in range(n):
  _e += (p[i] + 1) / 2
  if i >= k:
    _e -= (p[i - k] + 1) / 2
  e[i] = _e

print(max(e))

Solution (Python):
n,k=map(int,input().split())
p=list(map(int,input().split()))
pp=[]
su=0
for i in range(n):
    if i<k:
        su+=p[i]
    else:
        pp.append(su)
        su=su-p[i-k]+p[i]
pp.append(su)
ans=0.0
for i in range(len(pp)):
    j=(pp[i]+k)/2
    if ans<j:
        ans=j
print(ans)

Solution (Python):
class NumArray:
    def __init__(self, nums):
        if len(nums)>0:
            self.length = len(nums)
            self.tree = [0 for _ in range(2*self.length)]
            
            
            n = self.length
            i = n
            j = 0
            while i<2*n:
                self.tree[i] = nums[j]
                i += 1
                j += 1
            for i in range(n-1, 0, -1):
                self.tree[i] = self.tree[i*2] + self.tree[i*2 + 1]

    def update(self, pos, val):
        
        n = self.length
        pos += n
        self.tree[pos] = val
        while (pos > 0):
            left = pos
            right = pos
            if pos%2==0:
                right = pos + 1
            else:
                left = pos - 1
            self.tree[pos//2] = self.tree[left] + self.tree[right]
            pos //= 2
        
    def sumRange(self, l, r):
        if l > r:
            l, r = r, l
        
        n = self.length
        l += n
        r += n
        res = 0
        while l<=r:
            
            if l%2==1:
                res += self.tree[l]
                l += 1
            
            if r%2==0:
                res += self.tree[r]
                r -= 1
            l //= 2
            r //= 2
        return res
       


N, K = list(map(int, input().split()))
arr = list(map(int, input().split()))
seg_sum_tree = NumArray(arr)

mx_sum = 0
idx = 0
for i in range(N):
    if N <= i + K - 1:
        break
    val = seg_sum_tree.sumRange(i, i+K-1)
    if mx_sum <= val:
        mx_sum = val
        idx = i

ans = 0
for i in range(idx, idx+K):
    ans += (arr[i] + 1) / 2
print(ans)

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

for i in range(K-1):
    e += l[i]

for i in range(K-1,N):
    e += l[i]
    if (maxe < e):
        maxe = e
    e -= l[i-K+1]

print(maxe)

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

s = []
for i in range(K):
    s.append(p[i])

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

m += K

print(m / 2)

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

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

s = []
for i in range(len(p)-k+1):
    s.append(l[i+k]-l[i])

print(max(s))

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

res = sum(Es[0:K])
now = res
for i in range(0, N-K):
    now = now - Es[i] + Es[i+K]
    res = max(res, now)

print(res)

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

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

e = [0] * N

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

total = sum(e[0:K])
ans = total

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

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] * (p[i] + 1) / 2 / p[i]
    if i != 0:
        p[i] += p[i - 1]

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

print(ans)

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

Q = P/2 + 0.5

S = Q.cumsum()

if N == K:
    print(S[-1])
else:
	T = S[K:] - S[:-K]
	print(max(T))

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

    E = [((p + 1) / 2.0) for p in P]

    total = 0
    m = 0
    for i in range(N):
        if i < K:
            total += E[i]
        else:
            total += E[i] - E[i - K]

        if total > m:
            m = total

    print(m)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

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

ttl = 0
for i in range(K):
    d = l[i]
    ttl += (d+1)/2
M = ttl

for i in range(K,N):
    st = i-K
    d = l[st]
    ttl -= (d+1)/2
    dd = l[i]
    ttl += (dd+1)/2
    M = max(ttl,M)
print(M)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
S = [0, ]
for i in range(1, 1001):
    S.append(S[-1]+i)
E = [s/(i+1) for i, s in enumerate(S[1:])]
E = [0, ] + E

ans = 0
before_ans = 0
for i, p in enumerate(P):
    
    if i < K:
        ans += E[p]
        before_ans = ans - E[P[i-K+1]]
        continue
    tmp_ans = before_ans + E[p]
    ans = max(tmp_ans, ans)
    before_ans = tmp_ans - E[P[i-K+1]]
print(ans)

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

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

sum = 0

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

max_sum = sum

for i in range(n-k):
    sum -= ave(p[i])
    sum += ave(p[i+k])
    max_sum = max(sum, max_sum)

print(max_sum)

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

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

t = sum(p[:K])
m = (t + K) / 2
for i in range(1, N - K + 1):
    t = t - p[i - 1] + p[i + K - 1]
    m = max(m, (t + K)/2)

print(m)

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
  
num = sum(p[:k])
max_num = num

for i in range(k,n):
  num = num - p[i-k] + p[i]
  max_num = max(max_num, num)
  
  
print(max_num)

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]



answer = 0
l = expect_list[0:k]
p = sum(l)
for j in range(n-k+1):
    if p > answer:
       answer = p
    if j != n-k:
        p = p - expect_list[j] + expect_list[k+j]

print(answer)

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

Solution (Python):

N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0]

def calc(n):
  num =  n * (n+1) / 2
  return num / n

tmp = 0
for p in P:
  num = calc(p)
  tmp += num
  acc.append(tmp)

left = 0
right = K 
ans = 0

while right <= N:
  ans = max(ans, acc[right] - acc[left])
  left += 1
  right += 1

print(ans)

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

a = sum(p[0:k])
m = a
o = 0
for i in range(n - k):
    a += p[i + k] - p[i]
    
    if a > m:
        m = a
        o = i + 1
'''
q = []
for i in range(n):
    q.append((p[i] + 1) / 2)
'''
ans = 0


for j in range(o, o + k):
    ans += (p[j] + 1) / 2

print(ans)

Solution (Python):

import sys


def solve(N: int, K: int, p: "List[int]"):
    kitai=[0]*N
    for i in range(N):
        kitai[i]=(p[i]+1)/2

    ss=sum(kitai[0:K])
    ssmax=ss
    for i in range(N-K):
        ss-=kitai[i]
        ss+=kitai[i+K]
        if ssmax<ss:
            ssmax=ss

    print(ssmax)
    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):
N,K=map(int,input().split())
plist=list(map(int,input().split()))

exp_list=[]
for p in plist:
  exp_list.append((p+1)/2.0)


part_sum=sum(exp_list[:K])
ps_list=[part_sum]
for i in range(K,N):
  part_sum+=exp_list[i]-exp_list[i-K]
  ps_list.append(part_sum)
  

print(max(ps_list))

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


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

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

fir = 0
nex = k
num = sum(exp[:nex])
ma = 0
while nex <= n:
	if ma < num:
		ma = num
	if nex < n:
		num -= exp[fir]
		num += exp[nex]
		fir += 1
		nex += 1
	else:
		break
print(ma)

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

Solution (Python):

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

foo = sum(P[0:K])
ans = foo
for i in range(K,N):
    foo += P[i] -P[i-K]
    if ans < foo:
        ans = foo
print((ans+K)/2)

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

sm = [0, P[0]]
for pi in P[1:]:
    x = sm[-1] + pi
    sm.append(x)



mx = 0
mxi = 0
for i in range(N-K+1):
    x = sm[i+K] - sm[i]
    
    if x > mx:
        mx = x
        mxi = i



ans = 0
for i in range(K):
    p = P[mxi+i]
    
    ans += ((1 + p) * p / 2) / p
print(ans)

Solution (Python):
import sys

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

A=[]
for p in P:
    A.append(float(1+p)*p/2/p)

RUISEKI_A=[0]
for a in A:
    RUISEKI_A.append(RUISEKI_A[-1]+a)

ans=float("-inf")
for i in range(N-K+1):
    ans=max(ans,RUISEKI_A[i+K]-RUISEKI_A[i])

print ans

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

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

ans_ = ans
for i in range(n-k):
  ans_ = ans_ - d[p[i]] + d[p[k+i]]
  if ans_ > ans:
    ans = ans_
print(ans)

Solution (Python):

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

ans_ = ans

for left in range(1,n-k+1):
    ans_ -= (1+p[left-1])*p[left-1]/2/p[left-1]
    ans_ += (1+p[left+k-1])*p[left+k-1]/2/p[left+k-1]
    ans = max(ans, ans_)


print(ans)

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

def expec(n):
    return ((1/2 * n * (n+1) )/ n)

def maxSum(arr, n, k): 
    res = 0
    for i in range(k): 
        res += expec(arr[i])
    curr_sum = res 
    for i in range(k, n):       
        curr_sum += expec(arr[i]) - expec(arr[i-k])
        res = max(res, curr_sum) 
    return res 
  
print(maxSum(p, N, K))

Solution (Python):
n, k = map(int, raw_input().split())
a = [0] + map(int, raw_input().split())
for i in xrange(1, len(a)):
    a[i] += a[i - 1]
print (k + max(a[i] - a[i - k] for i in xrange(k, len(a)))) / 2.0

Solution (Python):
n, m = map(int, input().split())
a = list(map(int, input().split()))
tmp = []
t = 0
for i in a:
    t += (1/2) * (i+1)
    tmp.append(t)

mx = tmp[m-1]
for i in range(n-m):
    mx = max(mx, tmp[m+i]-tmp[i])
    
print(mx)

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

tab1 = [0]
tab1_tmp = 0
for pi in range(1, max(p) + 1):
    tab1_tmp += pi
    tab1.append(tab1_tmp)


tab2 = [0]
for i in range(N):
    tab2.append(tab1[p[i]] / p[i])


tab3 = [0]
tab3_tmp = 0
for i in range(1, N + 1):
    tab3_tmp += tab2[i]
    tab3.append(tab3_tmp)


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

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

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

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

import itertools
cumsum = list(itertools.accumulate(p))
cumsum = [0] + cumsum
ans = []

for i in range(K, N + 1):
    ans.append(cumsum[i] - cumsum[i - K])
    

print(max(ans))

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

m_r = sum(p[:K])
m_max = m_r

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

print(m_max / 2)

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

q = sum(P[:K])
m = q

for k in range(N-K+1):
    if k > 0:
        q = q - P[k-1] + P[K-1+k]
    if m < q:
        m = q

print((m+K)/2)

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

e_table = [0]
pre = 0
for i in range(1,1001):
    e_table.append((pre + i)/i)
    pre = pre + i

lis = [0] * K
SUM = 0
maximam = 0

for i, p in enumerate(input().split()):
    p = int(p)
    lis.append(e_table[p])
    SUM = SUM - lis[i] + lis[-1]
    maximam = max(maximam, SUM)
print(maximam)

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

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

edge=A[0]
s=sum(A[:K])
max_s=s
for i in range(1,N-K+1):
  s=s-edge+A[i+K-1]
  max_s=max(max_s,s)
  edge=A[i]
print(max_s)

Solution (Python):
import sys


TEST_INPUT = [
    """
    5 3
    1 2 2 4 5
    """,
    """
    4 1
    6 6 6 6
    """,
    """
    10 4
    17 13 13 12 15 20 10 13 17 11
    """
]
ANSWER = [
    "7.0",
    "3.5",
    "32.0"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, k, p_list):
    res = sum(p_list[:k])
    res_temp = res
    for i in range(n - k):
        res_temp -= p_list[i]
        res_temp += p_list[i + k]
        if res_temp > res:
            res = res_temp
    return (res + k) / 2


def input_and_solve(ih):
    n, k = map(int, ih.input().split())
    p_list = list(map(int, ih.input().split()))
    res = solve(n, k, p_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert abs(float(res) - float(ans)) < 0.00000001


if __name__ == "__main__":
    test()
    main()

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

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

m = tot = sum(ls[:k])
for i in range(1,n-k+1):
  tot = tot-ls[i-1]+ls[i+k-1]
  m = max(m, tot)
print(m)

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

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

M = [(1+p)/2 for p in P]
result = [0, ]

for i in range(1, N-K+1):
    result.append(result[-1] + M[i+K-1] - M[i-1])

print(sum(M[:K]) + max(result))

Solution (Python):
import numpy as np

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


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

p_arr = np.array(p_list)

p_mean = (p_arr + 1) / 2


sum_move = p_mean[:K].sum()


ans = sum_move

for i in range(N-K):
    sum_move = sum_move - p_mean[i] + p_mean[i+K]
    if ans < sum_move:
        ans = sum_move

print(ans)

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

def calc_e(v):
    if v % 2 == 0:
        return v // 2 + 0.5
    return v // 2 + 1

sum_max = 0
tmp = 0
max_i = 0
for i in range(N):
    sum_max += p[i]
    if i >= K - 1:
        
        if tmp < sum_max:
            
            max_i = i
            tmp = sum_max
        sum_max -= p[i-(K-1)]

ret = 0
for i in range(max_i-K+1,max_i+1):
    ret += calc_e(p[i])
print(ret)

Solution (Python):







import math
import string

def intinput():
    return int(input())

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

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

N, K = splitintinput()
p = listintinput()
tmpsum = 0
maxsum = 0
tmp = 0
for i in range(K):
    tmpsum += p[i]
maxsum = tmpsum
for i in range(K,N):
    tmpsum = tmpsum - p[i-K] + p[i]
    if tmpsum > maxsum:
        tmp = i
        maxsum = tmpsum

print((maxsum+K)/2)

Solution (Python):
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = [(1+x)/2 for x in p]
s = 0
start = 0
end = k-1
s = sum(p[start:end+1])
res = s
while end+1<n:
    s -= p[start]
    start+=1
    end+=1
    s += p[end]
    res = max(s,res)

print(res)

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

cumsum = [0]
for n in range(1, N+1):
  cumsum.append(cumsum[n-1] + (pn[n-1] + 1)/2)

max_exp = 0
for n in range(K, N + 1):
  max_exp = max(max_exp, cumsum[n] - cumsum[n-K])
print(max_exp)

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

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

aaaa=(ans+k)/2
print(aaaa)

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

sum_acc = []
tmp = 0
for i in range(N):
  tmp += (P[i]+1)/2
  sum_acc.append(tmp)
  

sum_max = 0  
for i in range(N):
  if(i == K-1):
   sum_tmp = sum_acc[i]
   sum_max = max(sum_tmp,sum_max)
  elif(i >= K): 
   sum_tmp = sum_acc[i]-sum_acc[i-K]
   sum_max = max(sum_tmp,sum_max)

print(sum_max)

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

s = sum(p[:k])
left = p[0]
m = s
for i in range(n - k):
    s = s - p[i] + p[i + k]
    m = max(m, s)

ans = (k + m) / 2
print(ans)

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

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

print(max(Y))

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

Solution (Python):
inputf = input

N, K = [int(x) for x in inputf().split(" ")]
P = [int(x) for x in inputf().split(" ")]
exp = [ (p*(p+1)//2)/p for p in P]
res = []
res.append(sum(exp[:K]))
for i in range(N-K):
    res.append(res[i]-exp[i]+exp[i+K])
print(max(res))

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

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

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

_sum=sum(p[:k])
_max=sum(p[:k])

for g in range(k,n):
    _sum=_sum+p[g]-p[g-k]
    _max = max(_sum,_max)
print(_max)

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

previous = sum(L[:k])
current_max = previous
for i in range(n-k):
    
    after = previous - L[i] + L[i+k]
    current_max = max(current_max, after)
    previous = after

print(current_max)

Solution (Python):
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
for i in range(N):
    l = p[i]
    p[i] = ((1+p[i]) * p[i])//2
    p[i] = p[i]/l
ans = 0
for i in range(K):
    ans +=p[i]
l = ans
for i in range(K,N):
    ans = ans + p[i] - p[i-K]
    l = max(l,ans)
print('{:.8f}'. format(l))

Solution (Python):
from itertools import accumulate
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    E=[0]*n
    for i,p in enumerate(P):
        E[i]=(1+p)/2
    Acc=[0]+list(accumulate(E))
    ans=0
    for i in range(n-k+1):
        ans=max(ans,Acc[i+k]-Acc[i])
    print(ans)
    
if __name__=='__main__':
    main()

Solution (Python):
import sys


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    p = [int(s) for s in sys.stdin.readline().strip().split()]

    pd = [0.0] * n
    for i in range(n):
        tot = (p[i] + 1) * p[i] // 2
        ex = tot / p[i]
        pd[i] = ex

    cand = sum(pd[:k])
    ans = cand
    for i in range(k, n):
        cand += pd[i]
        cand -= pd[i-k]
        ans = max(ans, cand)
    print(ans)


if __name__ == '__main__':
    main()

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

possibility=list(map(lambda x:(1+x)/2,p_l))


max_p=sum(possibility[0:k:1])
tmp=max_p
for i in range(1,len(possibility)-k+1):
    tmp+=possibility[i+k-1]-possibility[i-1]
    if tmp>max_p:
        max_p=tmp
        
print(max_p)

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

s = [e[0]]
for i in range(1, n):
    s.append(s[i-1]+e[i])

a = 0
for i in range(n-k+1):
    if i == 0:
        a = max(a, s[i+k-1])
    else:
        a = max(a, s[i+k-1] - s[i-1])
print(a)

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

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()
P = read_ints()


def ret_mean(X):
    return (X + 1) / 2


P_mean = [ret_mean(p) for p in P]

from itertools import accumulate
P_accum = [0] + list(accumulate(P_mean))

ans = 0

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

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