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



Sample input:
5 3
1 2 2 4 5


Sample output:
7.000000000000

Submission status: Accepted

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

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

tmp = 0
for i in range(K):
    tmp += P[i]
ans = tmp

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

print (ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().rstrip()

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

    sum_ls = tuple(accumulate(range(max(P) + 1)))
    acc_P = [0] + list(accumulate([sum_ls[p] / p for p in P]))

    ans = 0
    for i in range(N - K + 1):
        v = acc_P[i+K] - acc_P[i]
        if v > ans:
            ans = v
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
P_exp = np.array([0] + [(1+i)/2 for i in map(int, input().split())])
E_sum = np.cumsum(P_exp)

print((E_sum[K:]-E_sum[:-K]).max())

Submission status: Accepted

Solution code:
import numpy as np
n, k = list(map(int, input().split()))
p = np.array([0] + list(map(int, input().split())))
c = np.cumsum(p)
print((c[k:] - c[:-k] + k).max() / 2)

Submission status: Accepted

Solution code:
from functools import reduce
n, k = map(int, input().split())
p = list(map(int, input().split()))

cur = sum(map(lambda x: (x + 1) * 0.5, p[:k]))
max_value = cur
l, r = 1, k
while r < n:
    cur += (p[r] - p[l-1]) * 0.5
    max_value = max(max_value, cur)
    l += 1
    r += 1
print(max_value)

Submission status: Accepted

Solution code:
def main(N,K,p):
    sumi = 0
    ruiseki = [0] * (N+1)
    for i in range(N):
        ruiseki[i+1] = ruiseki[i] + p[i]
    for j in range(N-K+1):
        sumi = max(sumi, (ruiseki[j+K]-ruiseki[j]))
    return (sumi + K) / 2
N,K = map(int,input().split())
p = list(map(int,input().split()))
print(main(N,K,p))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int,input().split()))
s = [0] * (n-k+1)
s_0 = sum(p[0:k])
s[0] = s_0
for i in range(n-k):
    s[i+1] = s[i] + p[k+i] - p[i]

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

Submission status: Accepted

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

max_value = 0
for i in range(k):
    max_value += (p[i] + 1) * 0.5

l, r = 1, k
cur = max_value
while r < n:
    cur += (p[r] - p[l-1]) * 0.5
    max_value = max(max_value, cur)
    l += 1
    r += 1
print(max_value)

Submission status: Accepted

Solution code:
#累積和を使用
def main(n,k,p):
    maxVal = 0
    #期待値リスト・累積和リストの初期化
    kitai = [0] * n
    ruiseki = [0] * n
    kitai[0] = (p[0] + 1) / 2
    ruiseki[0] = (p[0] + 1) / 2
    #期待値・累積和の計算
    for i in range(1, n):
        kitai[i] = (p[i] + 1) / 2
        ruiseki[i] = ruiseki[i-1] + kitai[i]
    #累積和を使用して最大となる値を探索
    for i in range(k-1, n):
        val = ruiseki[i] - (ruiseki[i-k] if i-k >= 0 else 0)
        maxVal = max(maxVal, val)
    return maxVal

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
p = list(map(int, input().split()))

sp = [0 for _ in range(n-k+1)]
sp[0] = sum(p[:k])
mv = sp[0]
mi = 0
for i in range(1, n-k+1):
    sp[i] = sp[i-1]
    sp[i] -= p[i-1]
    sp[i] += p[i+k-1]
    if mv < sp[i]:
        mv = sp[i]
        mi = i

exp = 0
for i in range(mi, mi+k):
    exp += (p[i] + 1) / 2.0

print(exp)

Submission status: Accepted

Solution code:
def main2(n,k,p):
    maxVal = 0
    #期待値リスト
    kitai = [0] * n
    for i in range(n):
        kitai[i] = (p[i] + 1) / 2
    #先頭からK個の合計
    val = sum(kitai[:k])
    #kとnが同じ場合return
    if k == n:
        return val
    for i in range(k,n):
        #次の値は現在のvalにkitai[i]を足して、kitai[i-k]を引いた値
        val = val + kitai[i] - kitai[i-k]
        maxVal = max(maxVal, val)
    return maxVal

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

Submission status: Accepted

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

ans = sum(P[0:K])
tmp = sum(P[0:K])

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

Submission status: Accepted

Solution code:
n, k = input().split()
N = int(n)
K = int(k)
p = input().split()
P = list(map(int, p))
 
tmp = 0
num = 0
hoge = 0
ans = []
for i in range(N):
    tmp += (P[i] * (P[i] + 1) / 2 / P[i])
    ans.append(tmp)
    tmp -= tmp
    if i == (K-1):
        num = sum(ans[0:K])
        hoge = num
    elif i > (K-1):
        num = num - ans[i-K] + ans[i]
        if num > hoge:
            hoge = num
print(hoge)

Submission status: Accepted

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

S_i = [0]
for i in range(n):
    S_i.append(S_i[i] + p_list[i])    

# print(S_i)
result_max = 0
for j in range(k, n+1):
    cad_max = S_i[j] - S_i[j-k]
    result_max = max(cad_max, result_max)

print(result_max)

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
sum_max = 0
sum_temp = sum(p[0:K])
k_temp = 0
for k in range(1,N-K+1):
	sum_temp -= p[k-1]
	sum_temp += p[k+K-1]
	if sum_temp > sum_max:
		sum_max = sum_temp
		k_temp = k
ans = 0

for j in range(k_temp,k_temp+K):
	ans += (p[j]+1)/2
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
pl=list(map(int,input().split()))

cuml=[]
cum=0
for i in range(n):
    cum+=(pl[i]+1)/2
    cuml.append(cum)
mx=0
for i in range(n-(k-1)):
    if i==0:
        mx=max(cuml[i+k-1],mx)
    else:
        mx=max(cuml[i+k-1]-cuml[i-1],mx)
print('{:.9f}'.format(mx))

Submission status: Accepted

Solution code:
def exp(n):
  return n * (n + 1) / n / 2

N, K = map(int, input().split())
p = list(map(int, input().split()))
a = [0.0]
for i in range(N):
  a.append(a[i] + exp(p[i]))
m = 0
for i in range(N - K + 1):
  m = max(m, a[i + K] - a[i])
print(m)

Submission status: Accepted

Solution code:
N, K = map(int, input().rstrip().split())
Ps = [int(x) for x in input().rstrip().split()]

Ps_sum_list = []
Ps_sum = 0
for x in Ps:
    Ps_sum += x
    Ps_sum_list.append(Ps_sum)

max_val = 0
if K == 1:
    max_val = max(Ps)
    print((max_val + 1) / 2)
elif N == K:
    max_val = Ps_sum_list[-1]
    print((max_val + K) / 2)
else:
    for i in range(N - K):
        val = Ps_sum_list[i + K] - Ps_sum_list[i]
        if val > max_val:
            max_val = val
    print((max_val + K) / 2)

Submission status: Accepted

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


n, k = [int(i) for i in input().split()]
p = [f(int(i)) for i in input().split()]
ans = sum(p[:k])
a = ans
for i in range(k, n):
    a = a + p[i] - p[i - k]
    ans = max(ans, a)
print(ans)

Submission status: Accepted

Solution code:
# ruisekiwa by numpy

import numpy as np

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

b=np.concatenate([np.array([0]),np.cumsum(p)])

K_sum = b[K:] - b[:-K]
    
print((max(K_sum)+K)/2)

Submission status: Accepted

Solution code:
# ruisekiwa by itertools

from itertools import accumulate

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

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

ans=[]

for i in range(N-K+1):
    ans.append(b1[K+i]-b1[i])
    
print((max(ans)+K)/2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
s = list(map(int,input().split()))
s = np.array(s)
ans =  np.sum(s[:k])
a = ans
for i in range(n-k):
  a = a - s[i] + s[i+k]
  if a > ans:
    ans = a  
print((ans+k)/2)

Submission status: Accepted

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


def expect(n):
    res = (n + 1) / 2
    return res

p = list(map(expect, p))
ans_sum = sum(p[:k])
tmp_sum = ans_sum
idx = 0

for i in range(k, n):
    tmp_sum = tmp_sum + p[i] - p[i-k]
    if tmp_sum > ans_sum:
        ans_sum = tmp_sum

print(ans_sum)

Submission status: Accepted

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

total = sum(list_p[0:K])
max = total

for i in range(0,N-K) :
    total = total - list_p[i] + list_p[i+K]
    if total > max :
        max = total

print((max+K)/2)

Submission status: Accepted

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

Submission status: Accepted

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

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

_ans = sum(p[0:k])
ans = _ans
for x in range(n-k):
    # print(x, x + k)
    _ans = _ans - p[x] + p[x + k]
    ans = max(ans, _ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

E = []
for i in P:
    E.append((i+1)/2)
# print(E)

sum_E = [0, ]
for i in range(N):
    sum_E.append(sum_E[i] + E[i])
# print(sum_E)

sum_K = []
ans = 0
for i in range(N-K+1):
    if sum_E[i+K] - sum_E[i] > ans:
        ans = sum_E[i+K] - sum_E[i]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np

n,k = map(int, input().split())
p_list = np.fromstring(input(), int, sep=' ')

Cumulative_sum = np.zeros(n+1)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

print((length_k_sum_list.max()+k)/2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import numpy as np

n,k = map(int,input().split())
p_list = np.fromstring(input(),int,sep=' ')

Cumulative_sum = np.zeros(n+1, int)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

print((length_k_sum_list.max()+k)/2)

Submission status: Accepted

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

p = [((1+int(i))*int(i)/2)/int(i) for i in input().split()]

m = check = sum(p[0:K])
for i in range(K,N):
  check = check+p[i]-p[i-K]
  m = max(m,check)
print(m)

Submission status: Accepted

Solution code:
n , k = map(int, input().split())
p = list(map(int, input().split()))
p_accu = [p[0] + 1]

if k == 1:
    print((max(p) + 1 ) / 2 )
    exit()
elif k == n:
    print((sum(p) + n ) / 2 )
    exit()

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

S = p_accu[k-1]

for i in range(n - k):
    if S < p_accu[i+k] - p_accu[i]:
        S = p_accu[i+k] - p_accu[i]
    
print(S/2)

Submission status: Accepted

Solution code:
from itertools import accumulate
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))

P = list(accumulate([(i+1)/2 for i in p]))
P = [0] + P
ans = max([P[i+k]-P[i] for i in range(n-k+1)])
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = [(int(p) + 1) / 2. for p in input().split()]
sumexp = sum(p[:k])
maxexp = sumexp
for i in range(n-k):
  sumexp += p[i+k] - p[i]
  if sumexp > maxexp:
    maxexp = sumexp
print(maxexp)

Submission status: Accepted

Solution code:
import queue

nk = input()

po = input()

N = int(nk.split(' ')[0])
K = int(nk.split(' ')[1])

p = po.split(' ')
p2 = [(int(i) + 1 )/2 for i in p]

# print(p2)
q = queue.Queue()
rui = [p2[0]]
for i in range(1,N):
    # print(i)
    # print(rui[i-1],p2[i],rui[i-1] + p2[i+1])
    rui.append(rui[i-1] + p2[i])

# print(rui)

tes = 0
maxv = 0
for i in range(K-1,N):
    # print('turn',i)
    tes = rui[i]
    if(i >= K):
        tes -= rui[i-K]
    # print(tes)
    if(maxv < tes):
        maxv = tes
print(maxv)


# tes = 0
# maxv = 0
# for i in list(range(N-K + 1)):# 連続するKこの選び方のパターン  
#     tes = 0
#     for j in range(0,K-1):
#         tes += p2[i+j]
    
#     # print(tes)
#     if (tes > maxv):
#         maxv = tes

# # print('max',maxv)
# print(maxv)

Submission status: Accepted

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


l=sum(P[0:K])
k=l
for i in range(N-K):
  l = l-P[i]+P[i+K]
  if l>k:
    k=l

print((k+K)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = input().split()
n = int(n)
k = int(k)
p = list(map(int, input().split()))
if n==k:
	print((sum(p)+n)/2)
else:
	q = [p[0]]
	for i in range(n-1):
		q.append(q[i]+p[i+1])
	r = []
	for i in range(n-k):
		r.append(q[i+k]-q[i])
	r.sort(reverse=True)
	print((r[0]+k)/2)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
p=list(map(int, input().split()))
numset=[]
sexp=[]
tmp=0
ans=0
for i in range(max(p)+1):
  tmp=tmp+i
  numset.append(tmp)
exp=[]
for i in p:
  exp.append(numset[i]/i)
sexp.append(0)
s=0
for i in exp:
  s=s+i
  sexp.append(s)
for i in range(n-k+1):
  ans=max(ans, sexp[k+i]-sexp[i])
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
A = [(1+int(i))/2 for i in input().split()]
Sum = [0 for i in range(n+1)]
for i in range(n):
  Sum[i+1] = Sum[i]+A[i]
ans = 0
#print(Sum)
for i in range(n+1):
  if i+k<n+1:
    ans = max(ans,Sum[i+k]-Sum[i])
print(ans)

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))
p = list(map(int, input().split()))
p2 = [p[i]*0.5 + 0.5 for i in range(N)]
size = N + 1
cusum = [0] * size
max = 0

for i in range(N):
    cusum[i+1] = cusum[i] + p2[i]

for i in range(N-K+1):
    tmp = cusum[i+K] - cusum[i]
    if max < tmp:
        max = tmp
print(max)

Submission status: Accepted

Solution code:
from itertools import accumulate


N, K = map(int, input().split())
P = list(map(int, input().split()))
E = [(p+1)/2 for p in P]

cum = [0]
cum.extend(list(accumulate(E)))

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

print(ans)

Submission status: Accepted

Solution code:
n, k = list(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[i+k]
  if m < s:
    m = s
print((m+k)/2)

Submission status: Accepted

Solution code:
[N,K]=list(map(int, input().split()))
p=list(map(int, input().split()))

def ex(p,n):
    return (p[n]+1)/2


list=[]
s=0
for i in range (0,N):
    s=s+ex(p,i)
    list.append(s)

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

Submission status: Accepted

Solution code:
import numpy as np

n,k = map(int,input().split())
p_list = np.fromstring(input(), np.int64, sep=' ')

Cumulative_sum = np.zeros(n+1, np.int64)
Cumulative_sum[1:] = p_list.cumsum()

length_k_sum_list = Cumulative_sum[k:] - Cumulative_sum[0:-k]

ans = (length_k_sum_list.max() + k) / 2

print(ans)

Submission status: Accepted

Solution code:
import sys
 
ma = {}
def _sum(n):
    if not n in ma:
        ma[n] = sum(range(1,n+1))
    return ma[n]

def ev(v):
    return _sum(v) * 1.0/v
 
N, K = [int(x) for x in sys.stdin.readline().strip().split(" ")]
p = [ev(int(x)) for x in sys.stdin.readline().strip().split(" ")]
 

cur = sum([p[i] for i in range(K)])
_max = cur

i = K-1
j = 0

while i < N - 1:
    cur -= p[j]
    i += 1
    j += 1
    cur += p[i]
    if _max < cur:
        _max = cur

print(_max)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
l = list(map(int,input().split()))
 
def E(n):
  return (1 + n) / 2
 
j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
elif N == K:
  l2 = list(map(E, l))  
  print(sum(l2))
else:
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]

  l2 = list(map(E, t))
 
  print(sum(l2))

Submission status: Accepted

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

P = [(v+1)/2 for v in P]

acum = [0]*(n+1)
for i in range(n):
  acum[i+1] = acum[i] + P[i]
  
total = [0]*(n-k+1)
for i in range(n-k+1):
  total[i] = acum[i+k]-acum[i]  
  
print(max(total))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n,k=map(int,input().split())
	p=list(map(int,input().split()))
	
	s=sum(p[:k])
	ans=s
	
	for i in range(n):
		try:
			s=s-p[i]+p[i+k]
			ans=max(ans,s)
		except:
			break
	
	print((ans+k)/2)
	
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
# Ary=[(p+1)/2 for p in P]

Ary=[]
x=0
for p in P:
    x+=(p+1)/2
    Ary.append(x)
# print(Ary)
ans=Ary[K-1]
buf,left,right=0,0,0
for i in range(1,N-K+1):
    left,right=i,left+K
    # print(left,right)
    buf=Ary[right]-Ary[left-1]
    if buf>ans:
        ans=buf
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
 
an=0
an2=0
t=0
 
for i in range(n):
    if i<k:
        an+=((p[i]+1)/2)
        an2=an
    else:
        t=((p[i-k]+1)/2)
        if an+((p[i]+1)/2)-t>an2:
            an2=an+((p[i]+1)/2)-t
        an=an+((p[i]+1)/2)-t
            
print(an2)

Submission status: Accepted

Solution code:
def kitai(n):
  return (int(n)+1)/2

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

L=np.array([list(map(kitai, input().split()))]).reshape(-1)

from itertools import accumulate

acc = [0]+ list(accumulate(L)) # 0を忘れずに
ans = 0
for i in range(n-k+1):
  ans = max(ans,acc[i+k]-acc[i])
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
B=[(i+1)/2 for i in A]
m=M=sum(B[:k])
for i in range(n-k):
    m=m-B[i]+B[k+i]
    M=max(M,m)
print(M)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
m=M=sum(A[:k])
for i in range(n-k):
    m=m-A[i]+A[i+k]
    M=max(M,m)
print((M+k)/2)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [0] + [(1 + p) / 2 for p in P]
P_acc = list(accumulate(P))

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

print(ans)

Submission status: Accepted

Solution code:
def exp(a):
    return (a + 1) / 2

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

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

for i in range(1, n+1):
    if i <= k:
        tmp[i] = tmp[i-1] + exp(p[i-1])
    else:
        tmp[i] = tmp[i-1] - exp(p[i-k-1]) + exp(p[i-1])

print(max(tmp))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
pl=list(map(int,input().split()))

cuml=[]
cum=0
for i in range(n):
    cum+=(pl[i]+1)/2
    cuml.append(cum)
mx=0
#cumsum
for i in range(n-(k-1)):
    if i==0:
        mx=max(cuml[i+k-1],mx)
    else:
        mx=max(cuml[i+k-1]-cuml[i-1],mx)
print('{:.9f}'.format(mx))

Submission status: Accepted

Solution code:
import numpy as np

a1 = input()
a2 = input()

list1 = np.array(list(map(int,a1.split(" "))))

list2 = (np.array(list(map(int,a2.split(" "))))*10+10)/2

res = 0
now = 0

k = list1[1]
n = list1[0]
i = 0
while i < n:
    now = now + list2[i]
    if i>k-1:
        now = now - list2[i-k]
        res = max(res,now)
    res = max(res,now)
    i = i + 1
print(res/10)

Submission status: Accepted

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

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

t = sum(m[0:K])
result = t
for i in range(N - K):
    t += m[i + K] - m[i]
    if t > result:
        result = t
print(result)

Submission status: Accepted

Solution code:
from collections import deque

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

Ary=deque([])
ans,res,cnt=0,0,0
k=0

for i in range(N):
    cnt+=1
    k=(P[i]+1)/2
    Ary.append(k)
    res+=k
    if cnt<K:
        continue
    if ans<res:
        ans=res
    res-=Ary.popleft()

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

p = np.array([list(map(int, input().split()))]).reshape(-1)

p_a = 0
p_r = p[:k]
for j in p_r:
    if j == 1:
        p_a += 1
    else:
        p_a += (j + 1) / 2
p_b = p_a
for i in range(1, n-k+1):
    if (p[i-1] == 1):
        p_b -= 1
    else:
        p_b -= (p[i-1] + 1) / 2

    if (p[i+k-1] == 1):
        p_b += 1
    else:
        p_b += (p[i+k-1]  + 1) / 2
    if p_b > p_a:
        p_a = p_b
print(p_a)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

p = np.array([list(map(int, input().split()))]).reshape(-1)

sum_max = p[:k].sum()
mx = sum_max
index_max = -1
for i in range(1, n-k+1):
    mx += p[i+k-1]
    mx -= p[i-1]
    if mx > sum_max:
        sum_max = mx
        index_max = i
print(str((sum_max+k) / 2))

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
p_list=[0]
for i,p in enumerate(input().split()):
    p_i = int(p)
    p_list.append(p_list[i] + (p_i+1)/2)

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

Submission status: Accepted

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

Submission status: Accepted

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

exp = 0
for i in range(k):
 exp += (1 + p[i]) / 2
 exp_true = exp

for i in range(n-k):
 exp += (1 + p[i+k]) / 2
 exp -= (1 + p[i]) / 2
 if exp_true < exp:
   exp_true = exp

print(exp_true)

Submission status: Accepted

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

s = 0
ans = 0

for i, j in enumerate(p):
    s+= (j+1)/2
    if i == k-1:
        ans = s
    if i > k-1:
        s -= (p[i-k]+1)/2
        ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
res = 0
sum = 0
for i in range(N):
  sum += A[i]
  if i-K >= 0:
    sum -= A[i-K]
  res = max(res, sum)
print(0.5*(res+K))

Submission status: Accepted

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

# cumulated value
c_p = [0] * N
c_p[0] = p[0]

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

max_e = c_p[K - 1]

for i in range(K, N):
    e = c_p[i] - c_p[i - K]
    max_e = max(max_e, e)

print((max_e + K) / 2)

Submission status: Accepted

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

ma = sum(p[:K])
tmp = ma

for i in range(K,N):
    tmp += p[i]
    tmp -= p[i-K]
    if ma < tmp:
        ma = tmp

print((ma + K)/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int,input().split()))
ans = 0
cum = [0]
     
for i in range(len(p)):
    ex = (1 + p[i])/2
    p[i] = ex
        
for i in  range(len(p)):
    cum.append(p[i] + cum[i])
        
for i in range(K, N+1):
    ans  = max(ans, cum[i] - cum[i-K])
     
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
*p,= map(int, input().split())

s=[(p[n]+1)/2 for n in range(N)]
S=[0]*(N+1)

def make_S(n):
    S=[0]*(n+1)
    S[0]=0
    for i in range(n):
        S[i+1]=S[i]+s[i]
    return S
S=make_S(N)

def max_delta(n,k):
    max=-1000000
    for i in range(n-k+1):
        delta = S[i+k]-S[i]
        if delta>max:
            max=delta
    return max

print(max_delta(N,K))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    from itertools import accumulate

    n, k = map(int, input().split())
    p = [int(i) + 1 for i in input().split()]
    e = list(accumulate([0] + p))
    ans = 0

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

    print(ans / 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
P = list(map(int,input().split()))
sum_a = 0
index = 0

for i in range(k):
    sum_a += P[i]
num = sum_a
for j in range(1,n-k+1):
    num += P[j+k-1]
    #print(num)
    num -= P[j-1]
    #print(num)
    if(sum_a<num):
        index = j
        sum_a = num

total = 0.0
for m in range(index,index+k):
    total += sum(list(range(P[m]+1)))/P[m]
print(total)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int,input().split()))
ans = 0
cum = [0]

for i in range(len(p)):
    ex = (1 + p[i])/2
    p[i] = ex
    
for i in  range(len(p)):
    cum.append(p[i] + cum[i])
    
for i in range(K, N+1):
    ans  = max(ans, cum[i] - cum[i-K])

print(ans)

Submission status: Accepted

Solution code:
all,rolls=map(int,input().split())
inputList=list(map(int,input().split()))

sum = 0
sumList =[]

# 初めに全期待値計算
for i in range(all):
	inputList[i] = (inputList[i] + 1) / 2

# 最初の組み合わせの期待値計算
for i in range(rolls):
	sum = sum + inputList[i]
sumList.append(sum)

# 2番目以降の期待値計算
for i in range(all - rolls):
	sum = sum + inputList[i + rolls] - inputList[i]
	sumList.append(sum)

sumList.sort(reverse=True)
print(sumList[0])

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = sum(p[:K])
cur = ans
for i in range(K,N):
    cur += p[i] - p[i-K]
    if cur > ans:
        ans = cur
print((ans + K)/2)

Submission status: Accepted

Solution code:
N, K = (int(nk) for nk in input().split())

curr_S = 0
count = 1
max_ev = 0
index = 0
has_eval_sk = False
zero_e = []
for p_str in input().split():
    e = (int(p_str)+1) / 2
    zero_e.append(e)
    if has_eval_sk:
        curr_S += e - zero_e[index]
        max_ev = max(max_ev, curr_S)
        index += 1
    else:
        curr_S += e
        if count == K:
            max_ev = curr_S
            has_eval_sk = True
        count += 1

print(max_ev)

Submission status: Accepted

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

M=S=sum(p[:K-1])
for i in range(K-1,N):
  S+=p[i]
  M=M if M>S else S
  S-=p[i-K+1]

print((M+K)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
lis = list(map(int,input().split()))
total = 0

for i in range(m):
  total += lis[i] * 0.5 + 0.5
ans = total

for k in range(m,n):
  total -= lis[k-m]/2 - lis[k]/2
  ans = max(ans,total)
  
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
da = list(map(int,input().split()))
 
now = 0
for i in range(m):
    now += da[i]/2 + 0.5
ans = now
for i in range(m,n):
    now -= da[i-m]/2 - da[i]/2
    ans = max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
a= list(map(int, input().split()))
l=[]
for i in range(len(a)):
  l.append((a[i]+1)/2)
maxans=sum(l[0:k])
ans=sum(l[0:k])
for i in range(len(l)-k):
  ans=ans+l[i+k]-l[i]
  maxans=max(ans,maxans)
 
print(maxans)

Submission status: Accepted

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

max = 0
for i in range(n-k+1):
  if i == 0:
    s = sum(ps[i:i+k])
  else:
    s = s - (ps[i-1] - ps[i+k-1])
  if s > max:
    max = s
print((max + k) / 2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int,input().split()))
box = []
for i in p:
    box.append((i+1)/2)

sum_a = sum(box[:K])
max_a = sum_a
for i in range(N-K):
    max_a -= box[i]
    max_a += box[i+K]
    if max_a > sum_a:
        sum_a = max_a

print(sum_a)

Submission status: Accepted

Solution code:
# 累積和

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

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

cum = [0]
for i in range(len(e)):
    cum.append(e[i] + cum[i])

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
max = 0
S = 0
for i in range(len(P)):
    S += P[i]
    if i-K < 0:
        pass
    else:
        S -= P[i-K]
    if max < S:
        max = S

print((max+K)/2)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
tmp = sum(p[:k])
res = tmp
# スライドさせていく
for i in range(n - k):
    tmp -= p[i]
    tmp += p[i + k]
    res = max(res, tmp)
# 期待値は　例えば　k=6の時、(1+2+3+4+5+6)/2 =3.5 になり、
# 別の計算方法だと　(6+1)/2=3.5となる
print((res + k) / 2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(n+1)
S[1]=P[0]

for i in range(1,n):
    S[i+1]=S[i]+P[i]

ma=0
for i in range(k,n+1):
    s=S[i]-S[i-k]
    ma=max(ma,s)
print((ma+k)/2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [(i + 1) / 2 for i in c]
e = sum(d[:b])
f = e
for i in range(a - b):
	f -= d[i]
	f += d[i + b]
	if f > e:
		e = f
print(e)