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())
nums = list(map(int,input().split()))
ans = []

for i in range(N):
  ans.append((nums[i]+1)/2)

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

print(M)

Submission status: Accepted

Solution code:
import numpy
 
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*(N-K+1)

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

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

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  ans=ans+float(((p[i]*(p[i]+1))/2)*1/p[i])
print(ans)

Submission status: Accepted

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

for p in ps:
  es.append((1 + p) * p / 2 / p)

t = sum(es[0:k])
r = t

for i in range(k, n):
  t = t + es[i] - es[i - k]
  r = max(r, t)

print(r)

Submission status: Accepted

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

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

s = sum(ex[0:k])
t = s
for i in range(n-k):
    s = s-ex[i]+ex[i+k]
    t = max(t, s)

print(t/2)

Submission status: Accepted

Solution code:
N,K=(int(x) for x in input().split())
P=list(map(int, input().split()))
s=sum(P[0:K])
ans=[s]

for i in range(K,N):
    s=s+P[i]-P[i-K]
    ans.append(s)

S=max(ans)
print((S+K)/2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
query=[int(x) for x in input().split()]
N = query[0]
K = query[1]
L = list()
L = [int(x) for x in input().split()]



def prob(x):
    out = 0.0

    out = (x+1)/2

    return out


# final = 0.0
# answer=list()
# for i in range(0, N):
#     final=0.0
#     for j in range(i, K+i):
#         if K+i<=N:
#             div = L[j]
#             final = final + prob(div)
#     answer.append(final)
#
# print("%14.12f"%max(answer))


res=0.0
tres=0.0
for i in range(0,K):
    tres+=prob(L[i])
    res=max(res,tres)
rindex=K
lindex=0
while rindex<N:
    tres=tres-prob(L[lindex])+prob(L[rindex])
    rindex+=1
    res=max(res,tres)
    lindex+=1
print("%14.12f"%res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
s=sum(l[:k])
ma=s
i=0
while i+k<len(l):
    s-=l[i]
    s+=l[i+k]
    ma=max(ma,s)
    i+=1
print((ma+k)/2)

Submission status: Accepted

Solution code:
pre_N_list=input()
N_list=pre_N_list.split(' ')
N=int(N_list[0])
K=int(N_list[1])
p=input()
p_list=p.split(' ')
exp=[]
com=[]
com_sum=[]
t=0
for i in range(N):
  p_list[i]=int(p_list[i])
for i in range(1000):
  exp.append((1+i+1)*(i+1)/(2*(i+1)))
#これでexp[i]にはその最大面の値がi+1のサイコロ期待値が格納される。#
for i in range(N):
  com.append(exp[p_list[i]-1])
#print('期待値：',com)#
#com[]はpが[p1 p2 p3 p4・・・]のときcom=[exp[p1] exp[p2] exp[p3] exp[p4]・・・]である。#
for i in range(N):
  t+=com[i]
  com_sum.append(t)
#print('期待値の和', com_sum)#
#com_sum=[com[0] com[0]+com[1] com[0]+com[1]+com[2] ・・・]#
com_dif=[]
com_dif.append(com_sum[K-1])
for i in range(N-K):
  com_dif.append(com_sum[i+K]-com_sum[i])
#print('期待値の差', com_dif)#
print(max(com_dif))

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

def main():
    
    # sys.stdin = open('input154d.txt')

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    
    s = [0] + p
    s = list(accumulate(s))

    # print(p)
    # print(s)
    maxp = 0
    idx = 0
    for i in range(n - k + 1):
      nowp = s[i + k] - s[i]
      # print(i)
      # print(nowp)
      if maxp < nowp:
        maxp = nowp
        idx = i

    # print(idx)

    sump = 0
    for j in range(idx, idx+k):
      sump += p[j] * (p[j] + 1) / 2 / p[j]

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

Submission status: Accepted

Solution code:
n,k,*p=map(int,open(0).read().split())
l=[]
l.append(sum(p[:k]))
for i in range(k,n):
    l.append(l[-1]+p[i]-p[i-k])
ind=l.index(max(l))
ans=0
for i in range(k):
    ans += (1+p[ind+i])/2
print(ans)

Submission status: Accepted

Solution code:
n,k = map(lambda x: int(x),input().split())
p = list(map(lambda x: (int(x) + 1)/2,input().split()))
ruiseki = [0]
max = 0
for i in range(n) :
    ruiseki.append(ruiseki[i]+p[i])

for j in range(n - k + 1):
    if max < (ruiseki[j+k] - ruiseki[j]) :
        max = (ruiseki[j+k] - ruiseki[j])


print(max)

Submission status: Accepted

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

total = sum(P[:k])
tmp = total
start = 0
for i in range(0, n - k):
    tmp = tmp - P[i] + P[i + k]
    if total < tmp:
        total = tmp
        start = i + 1

ret = 0
for i in range(start, start + k):
    ret += (P[i] + 1) / 2

print(ret)

Submission status: Accepted

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

S = 0
maxsum = 0
for i in range(K):
    S += (p[i]+1)/2

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

if(maxsum < S):
    maxsum = S

print(maxsum)

Submission status: Accepted

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

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

ans = 0
max_s = s[0]
max_i = 0
for i in range(k, n):
    s[i-k+1] = s[i-k] + p[i] - p[i-k]
    if s[i-k+1] > max_s:
        max_s = s[i-k+1]
        max_i = i-k+1

ans = 0
for i in range(max_i, max_i+k):
    ans += p[i] * (p[i]+1) / 2 / p[i]

print("%.8f" % ans)

Submission status: Accepted

Solution code:
import numpy as np

N,K = [int(i) for i in input().split()]
n = np.array([int(i) for i in input().split()])
n=(n+1)
t=np.empty(N+1)
t[0] = 0
t[1:]=np.cumsum(n)
print(max(t[K:]-t[:-K])*0.5)

Submission status: Accepted

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

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

print((ans + k) * 0.5)

Submission status: Accepted

Solution code:
N , K= map(int, input().split())
A =list(map(int, input().split()))
B=[0 for _ in range(N+1)]
for i in range(N):
    A[i] = (A[i]+1)/2
for i in range(N):
    B[i+1]=B[i]+A[i]

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

print (ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


prefix = [0] * len(nums)
prefix[0] = nums[0]
for i in range(1,len(nums)):
    prefix[i] = prefix[i-1] + nums[i]

mm = prefix[k-1]
idx = 0
for i in range(k,len(nums)):
    curr = prefix[i] - prefix[i-k]
    if curr > mm:
        mm = curr
        idx = i

s = 0
for i in range(idx-k+1,idx+1):
    s += (nums[i]+1)/2
print(s)

Submission status: Accepted

Solution code:
import numpy as np

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

p_mapped = [(i + 1) / 2 for i in p]
p_m_cumsum = np.cumsum(p_mapped)

max = 0
for i in range(len(p_m_cumsum)-K+1):
    if i != 0:
        answer = p_m_cumsum[i+K-1] - p_m_cumsum[i-1]
    else:
        answer = p_m_cumsum[i+K-1]
    if answer >= max:
        max = answer
print(max)

Submission status: Accepted

Solution code:
import numpy as np

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

e = (p + 1) / 2

# print(e)

cum_e = np.zeros(N + 1)
cum_e[1:] = np.cumsum(e)

# print(cum_e)

s = cum_e[K:] - cum_e[:-K]

print(max(s))

Submission status: Accepted

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

for i in range(N):
    l.append((P[i] + 1) / 2)

n = 0
for i in range(N):
    n += l[i]
    l[i] = n

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

print(ans)
# print(l)

Submission status: Accepted

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

#output
import numpy as np
p = np.array(p)
q = np.cumsum(p)

answer = (K + q[K-1])/2
for i in range(K, N):
    answer = max(answer, (K + q[i] - q[i-K])/2)

print(answer)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
s = m = sum(p[:K])
for i in range(K,N):
    s += p[i]-p[i-K]
    m = max(m,s)
print((m+K)/2)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

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

S = []
for i in range(len(P)):
    if(i > 0):
        S.append(P[i]+S[i-1])
    else:
        S.append(P[0])
# print(S)

max = S[K-1]
for i in range(len(S)-K):
    a = S[i+K]-S[i]
    # print(a)

    if(a > max):
        max = a

# max = 0

# for i in range(len(P)-K+1):
#     num = 0
#     for j in range(K):
#         num += P[i+j]
#         # print(P[i+j],end=" ")
#     # print(num)
#     if(max < num):
#         max = num

print("{0:6f}".format(max))

Submission status: Accepted

Solution code:
n,k = tuple(map(int,input().split())) 
N = list(map(int,input().split()))
s = sum(N[0:k])
m = sum(N[0:k])

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
tu=tuple(map(int,input().split()))
l=[0]*(N+1)
l[0]=0
ans=0
for i in range(1,N+1):
  l[i]=l[i-1]+(tu[i-1]+1)/2
  if i>=K:
    ans=max(ans,l[i]-l[i-K])
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
from itertools import accumulate
p = list(map(lambda x:(int(x)+1)/2,input().split()))
S = sum(p[:K])
M = S
for i in range(N - K):
    S -= p[i]
    S += p[i + K]
    M = max(M,S)
print(M)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
from itertools import accumulate
A = [0] + list(accumulate(map(lambda x:(int(x)+1)/2,input().split())))
M = 0
for x in range(N - K +  1):
    M = max(M,A[x + K] - A[x])
print(M)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
from itertools import accumulate
A = [0] + list(accumulate(list(map(lambda x:(int(x)+1)/2,input().split()))))
M = 0
for x in range(N - K +  1):
    M = max(M,A[x + K] - A[x])
print(M)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = list(map(int,input().split()))
p = list(map(lambda x:(x+1)/2,p))
from itertools import accumulate
A =  [0] + list(accumulate(p))
M = 0
index = 0
for x in range(N - K +  1):
    M = max(M,A[x + K] - A[x])
print(M)

Submission status: Accepted

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

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

print((Max + K) / 2)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
P = list(map(int,input().split()))
P = [p+1 for p in P]
sm = sum(P[:K])  # 先頭のK個の和を計算
ans = sm  #  最大値（答え）を保存する
for i in range(N-K):
    sm = sm - P[i] + P[K+i]  # 窓をずらす
    ans = max(ans, sm)  # 最大値（答え）を更新
print (ans/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy

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

K = A[1]
N = A[0]

P = list(map(float, input().split()))

EP = list(map(lambda x: (1+x)/2, P))

cumEP = list(numpy.cumsum(EP))

new_list = []

if N>K:
    for val in range(N-K):
        new_list.append(cumEP[val+K]-cumEP[val])
    print(max(new_list))
else:
    print(sum(EP))

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
P = (np.array(input().split(), dtype=np.int64) + 1) / 2

expect = P[:K].sum()
ans = expect
for i in range(K, N):
    expect += P[i] - P[i - K]
    ans = max(ans, expect)
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
Q = list()
R = [0]
result = 0

for i in P:
  Q.append((i+1)/2)

for i in range(N):
  R.append(R[i] + Q[i])

for i in range(N - K + 1):
  result = max(result,R[i+K]-R[i])

print(result)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

b=[0]+list(accumulate(x))

mm=0
inx=-1
for i in range(len(b)-k):
 if b[i+k]-b[i]>=mm:
  inx=i
  mm=b[i+k]-b[i]


ans=0
for j in range(inx,inx+k):
  ans+=((p[j]*(p[j]+1))*0.5)*(1/p[j])

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

b=[0]+list(accumulate(x))

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

b=[0]+list(accumulate(x))

'''
bb=[0]
for i in range(1,n+1):
 bb.append(bb[i-1]+x[i-1])

print(b)
print(bb)
'''

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

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_cumsum = [0]
for p in map(int, input().split()):
  p_cumsum += [p_cumsum[-1]+p]
pk_max = 0
for i in range(k, n+1):
  pk_max = max(pk_max, p_cumsum[i]-p_cumsum[i-k])
print((pk_max+k)/2)

Submission status: Accepted

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

ans = s = sum(Q[:K])
for i in range(K, N):
    q0 = Q[i - K]
    q1 = Q[i]
    s += (q1 - q0)
    ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
import sys

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
P = [i for i in P if 1 <= i and i <= 10**3]
Q = [] # 期待値リスト
S = [] # 累積和
T = [] # 隣接するK個の期待値
s=0

if not 1 <= K <= N <= 2*10**5:
    sys.exit()

for i in range(N):
    # q = sum(range(1, P[i]+1)) / P[i]
    q = (1 + P[i]) / 2
    Q.append(q)
    s += q
    S.append(s)
    if i == K-1:
        T.append(S[i])
    if i > K-1:
        T.append(S[i]-S[i-K])
print(max(T))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    N, K= map(int, input().split())
    p = list(map(int, input().split()))
    # 累積和
    p = [0] + list(accumulate(p))

    # 累積和が最大になる区間、期待値は(1+p)/2、k個分なので以下の式。
    print((max(b - a for a, b in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
  	main()

'''
5 3
1 2 2 4 5

10 4
17 13 13 12 15 20 10 13 17 11
'''

Submission status: Accepted

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


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum


print(mmax)

Submission status: Accepted

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

Submission status: Accepted

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

p_sum = [0] * (n + 1)

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

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, k = na()
p = np.array(na())
p = (1+p)/2
now = sum(p[:(k)])
ans = now
for i in range(0, n-k):
    now = now - p[i] + p[i+k]
    ans = max(now, ans)
print("{:.8f}".format(ans))

Submission status: Accepted

Solution code:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
if (n != k):
    pp = list(accumulate(p))
    ppp = [pp[i + k] - pp[i] + k for i in range(len(p) - k)]
    print((max(ppp)) / 2)
else:
    print((sum(p) + n) / 2)

Submission status: Accepted

Solution code:
Input1 = [int(_) for _ in input().split(" ")]
Input2 = [(int(i)+1)/2 for i in input().split(" ")]

sum_ = sum(Input2[:Input1[1]])
Max = sum_
for j in range(Input1[0]-Input1[1]):
    sum_ = sum_-Input2[j]+Input2[j+Input1[1]]
    if Max  < sum_:
        Max = sum_
        
print(Max)

Submission status: Accepted

Solution code:
def main():
  n, k = map(int, input().split())
  p = list(map(int, input().split()))
  q = [(x+1)/2 for x in p]
  cur = sum(q[:k])
  ans = cur
  for i in range(k, n):
    cur = cur - q[i-k] + q[i]
    ans = max(cur, ans)
  print(ans)
    

if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy

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

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

S = numpy.cumsum(PP).tolist()

r = -1
for i, ss in enumerate(S[K-1:]):
    r = ss if i == 0 else max(r, ss - S[i - 1])

print(r)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
acc = [0.0]
for x in map(int, input().split()):
    acc.append((1 + x) / 2)
    acc[-1] += acc[-2]
ans = 0.0
for start in range(N - K + 1):
    ans = max(ans, acc[start + K] - acc[start])
print(ans)

Submission status: Accepted

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

import numpy as np

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

for i in range(n):
    #exps.append(sum(list(range(1, p[i]+1)))/p[i])
    exps.append((1+p[i])/2)

exps = np.array(exps)
cumexps = exps.cumsum()
cumexps = np.insert(cumexps, 0, 0)

#print(exps)
#print(cumexps)

ans = -1
for i in range(n-k+1):
    tmp = -cumexps[i] + cumexps[i+k]
    if ans <= tmp:
        ans = tmp 

print(ans)

Submission status: Accepted

Solution code:
# D - Dice in Line
from itertools import accumulate #累積和
n,k,*p = map(int,open(0).read().split())
ac = [0] + list(accumulate(p))
a = 0
for i in range(n-k+1): a = max(a, ac[i+k] - ac[i])
print((a+k)/2)

Submission status: Accepted

Solution code:
def kitaiti(number):
 return (1 + number)/2
def ruisekiwa(mylist):
    s = [0]
    t = 0
    for i in range(len(mylist)):
        t += mylist[i]
        s.append(t)
    return s
def wa(mylist,K):
    a = []
    i = 0
    while K + i < len(mylist):
        a.append(mylist[K + i]-mylist[i])
        i += 1
    return max(a)
N,K = (int(i) for i in input().split())
kitaiti = [kitaiti(int(x)) for x in input().split()]
print(wa(ruisekiwa(kitaiti),K))

Submission status: Accepted

Solution code:
n ,k = map(int ,input().split())
hai = list(map(lambda x:(int(x)+1)/2 ,input().split()))
hait= hai[:k]
ans = tmp = sum(hait)
for i in range(k,n):
  tmp = tmp - hai[i-k] + hai[i]
  if ans < tmp:
    ans = tmp
print(ans)

Submission status: Accepted

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

## 期待値を事前に計算しておく
P = []
for p in _P:
  if p == 1:
    P.append(1)
  elif p%2 == 0:
    P.append(p//2+0.5)
  else:
    P.append(p//2+1)

## 最初に求められるところを求めたのち、一個ずつずらしていく
ans = sum(P[:K])
_ = ans
for x in range(1,N-K+1,1):
  ## 1個ずらして計算
  _ -= P[x-1]
  _ += P[x+K-1]
  
  ## 今までの最大値との比較
  ans = max(ans, _)
      
      
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e
#print(Data2)
sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)

Submission status: Accepted

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

tmp = 0
m = 0
index = 0
for i in range(n - k + 1):
    if m < R[i + k - 1] - tmp:
        m = R[i + k - 1] - tmp
        index = i
    tmp = R[i]
ans = 0

for i in range(index, index + k):
    ans += (p[i] + 1) / 2
print(ans)

Submission status: Accepted

Solution code:
N,K  = map(int,input().split())
nums = list(map(int,input().split()))
# preprocess
#
for i in range(len(nums)):
    nums[i] =  (nums[i] + 1)/2

ans = -1
ans = cand =  sum(nums[:K])
for i in range(K,len(nums)):
    cand = cand - nums[i - K] +  nums[i]
    ans = max(cand,ans)

print(ans)

Submission status: Accepted

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

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)

Submission status: Accepted

Solution code:
n, k = map(int, input().split(' '))
p = list(map(int, input().split(' ')))
m = []
t = sum(p[:k])
idx = 0
m.append(t)
for i in range(1, n - k + 1):
    t -= p[i - 1]
    t += p[i + k - 1]
    m.append(t)
mi = m.index(max(m))
pp = p[mi: mi + k]
pp.sort()
sg = 0
tp = 1
r = 0
for i in pp:
    for j in range(tp, i + 1):
        sg += j
    tp = i + 1
    r += sg / i
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Dice in Line
n,k,*p = map(int,open(0).read().split())
a = s = sum(p[:k]) + k
for i in range(n-k):
    s += p[i+k] - p[i]
    a = max(a, s)
print(a/2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import accumulate

def solve(N: int, K: int, p: "List[int]"):
    accum_p = [0] + list(accumulate(p))
    max_index = 0
    max_value = 0

    for i in range(N-K+1):
        cur = accum_p[i+K]-accum_p[i]

        if cur > max_value:
            max_index = i
            max_value = cur
    

    ep = []
    for i in range(max_index,max_index+K):
        ep.append((1+p[i])/2)
    print(sum(ep))
    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))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
SUM_P=sum(p[0:K])
all_sum_p=[SUM_P]
for i in range(N-K):
    SUM_P=SUM_P-p[i]+p[i+K]
    all_sum_p.append(SUM_P)
print((max(all_sum_p)+K)/2)

Submission status: Accepted

Solution code:
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    ls = [0] * n
    for i, v in enumerate(a):
        ls[i] += (((1 + v) * v) // 2) / v
    ls = [0] + list(itertools.accumulate(ls))
    mt = 0
    for i in range(k, n + 1):
        mt = max(mt, ls[i] - ls[i-k])
    print(mt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
import numpy as np
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial

sys.setrecursionlimit(10**7)
N, K = map(int, input().split())
pss = list(map(int, input().split()))
ps = [(p+1)/2 for p in pss]

acc = [0] * N
acc[0] = sum(ps[:K])
for i in range(1, N-K+1):
    acc[i] = acc[i-1] - ps[i-1] + ps[i+K-1]

mi = np.argmax(acc)

print(sum(ps[mi:mi+K]))

Submission status: Accepted

Solution code:
#サイコロの目からk個ずつ順にループで切り出して和をリストするとTLE
#累積和のリストから、k個の和のリスト → 期待値のリストでTLE解消

from itertools import accumulate

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

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

q = [] #累積和'p'からから求めたk個ずつの和
r = [] #出目の期待値
for i in range(n-k+1):
    q.append(p[i+k] - p[i])
    r.append((q[i] + k) / 2)

print(max(r))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e
#print(Data2)
sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print((m+K)/2)

Submission status: Accepted

Solution code:
from itertools import accumulate

n, k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)

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

#print(p)

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

print(max(q))

Submission status: Accepted

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

sum_array = [0] * (N + 1)
for i in range(1, N+1):
    exp = (1 + P[i-1]) / 2
    sum_array[i] = sum_array[i-1] + exp

expectation = 0
for i in range(K, N+1):
    expectation = max(sum_array[i] - sum_array[i-K], expectation)
    # print(expectation)

print(expectation)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
num = list(map(int, input().split()))
 
# 各サイコロの期待値を出す
expect = []
for i in range(N):
  expect.append((1 + num[i]) / 2)
 
# 累積和を作る
cs = [0]
for i in range(N):
    cs.append(cs[i]+expect[i])

max = 0
for i in range(K, N+1): # 配列0番目に初期値0が増えてるので1足す
  if max < cs[i] - cs[i-K]:
    max = cs[i] - cs[i - K]
print(max)

Submission status: Accepted

Solution code:
N,K= map(int,(input().split()))
p = list(map(int,input().split()))
rui_p=[]
rui_p.append(0)
sum_p=[]
for i in range(N):
  rui_p.append(rui_p[i]+p[i])
for j in range(K,N+1):
  sum_p.append(rui_p[j]-rui_p[j-K])

msp=max(sum_p)
ans=(msp/2)+(0.5*K)
print(ans)

Submission status: Accepted

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

value = [0]*N
k_list = []

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

for i in range(N):
    value_list[i] = value_list[i-1] + value[i]

value_list.append(0)

for i in range(N-K+1):
    k_list.append(value_list[i+K-1]-value_list[i+K-(K+1)])
    
print(max(k_list))

Submission status: Accepted

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

# 各サイコロの期待値を出す
expect = []
for i in range(N):
  expect.append((1 + num[i]) / 2)

# 累積和を作る
cs = [0]
for (i, number) in enumerate(expect):
  cs.append(cs[i] + expect[i])

max = 0
for i in range(K, N+1): # 配列0番目に初期値0が増えてるので1足す
  if max < cs[i] - cs[i-K]:
    max = cs[i] - cs[i - K]
print(max)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
q = []
for pp in p:
  q += [(pp+1)/2]
ans = 0
tem = sum(q[:K])
for i in range(K,N+1):
  if i != K: tem += q[i-1] - q[i-K-1]
  ans = max(ans, tem)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N, K = rip()
    A = ria()

    sum = [0] * (N + 1)
    for i in range(N):
        sum[i + 1] = sum[i] + A[i]
    
    ma = 0
    for i in range(N - K + 1):
        ma = max(ma, sum[i + K] - sum[i])
    print((ma + K) / 2.0) 



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
S=[0]*(N+1)


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