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()))
def expected_value(p):
  E = []
  for i in p:
    E.append(float((i+1)/2))
  return E
def cumulative_sum(E, n):
  s = []
  for i in range(n):
    if i == 0:
      s.append(0)
    s.append(s[i]+E[i])
  return s
def max_search(k,n,p):
  ans = []
  E = expected_value(p)
  S = cumulative_sum(E, n)
  for i in range(int(n-k+1)):
    ans.append(S[i+k] - S[i])
  return max(ans)
print(max_search(k,n,p))

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(n-k+1):
   ans=max(ans,S[i+k]-S[i])
print((ans+k)/2)

Submission status: Accepted

Solution code:
import numpy as np

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

exp = (p + 1) / 2
max_sum_exp = sum(exp[0:k])
sum_exp = max_sum_exp
for i in range(n-k):
    sum_exp = sum_exp + exp[k+i] - exp[i]
    max_sum_exp = max(sum_exp, max_sum_exp)

print(max_sum_exp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
N, K = map(int, input().split())
P = list(map(int, input().split()))
E = [0]
E.append(sum([i for i in range(1, P[0] + 1)])/P[0])
for i in range(1,N):
    p = P[i]
    E.append(E[i] + ((1+p) / 2))
r = K
ans = 0
while r < N + 1:
    ans = max(ans, E[r] - E[r - K])
    r += 1
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = [(1+int(x)) / 2.0 for x in input().split()]

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    ans = 0.0
    count = 0
    tmp = 0.0
    for i in range(n):
        if count == k:
            tmp = tmp - (1.0 + float(p[i-k])) / 2.0 + (1.0 + float(p[i])) / 2.0
            if tmp > ans:
                ans = tmp
        else:
            tmp += (1.0 + float(p[i])) / 2.0
            ans = tmp
            count += 1

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

temp = 0

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

ans = temp

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

print(ans)

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 + 1)
    tm = 0
    for i, v in enumerate(a):
        ls[i + 1] = (((1 + v) * v) // 2) / v
    ls = list(itertools.accumulate(ls))
    for i in range(k, n + 1):
        tm = max(tm, ls[i] - ls[i-k])
    print(tm)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P = [int(i) for i in input().split()]
total, maxS = 0, 0
S = [0]
for p in P:
    total += p*(p+1)/2/p
    S.append(total)

for i in range(N-K+1):
    if maxS < S[i+K]-S[i]:
        maxS = S[i+K]-S[i]
print(maxS)

Submission status: Accepted

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

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

    P_sum = [0]
    tmp = 0
    for i in range(N):
        tmp += P_e[i]
        P_sum.append(tmp)

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

    print(max)
    return 0
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
a = sum(p[:k])
for i in range(n-k+1):
    if i != 0:
        a = a-p[i-1]+p[i+k-1]
    if a > s:
        s = a
        
print((s+k)/2)

Submission status: Accepted

Solution code:
from functools import reduce

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

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(max_mean, cur)
print(max_mean)

Submission status: Accepted

Solution code:
from functools import reduce

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

max_mean = reduce(lambda a, b: a + 0.5 * (b + 1), p[:k], 0)
cur = max_mean
for i in range(k, n):
    cur += (0.5 * (p[i] - p[i - k]))
    max_mean = max(cur, max_mean)
print(max_mean)

Submission status: Accepted

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

lastSum = sum(inList[0: K])
maxNum = lastSum

for indx in range(1, N - (K - 1)):
  maxNum = max(lastSum - inList[indx-1] + inList[indx+K-1], maxNum)
  lastSum = lastSum - inList[indx-1] + inList[indx+K-1]

print((maxNum + K) / 2)

Submission status: Accepted

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

#期待値
E=[]
for i in range(0,N):
    E.append((1+P[i])/2)
    
wa=[]
wa.append(sum(E[0:K]))
for j in range(1, N-K+1):
    wa.append(wa[j-1] - E[j-1] + E[j+K-1])
print(max(wa))

Submission status: Accepted

Solution code:
N, K= map(int, input().split())
p = list(map(int, input().split()))
 
tmp = sum(p[:K])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp
 
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])
max = tmp
for i in range(N-K):
    tmp += (p[i+K]-p[i])
    if tmp>max:
        max = tmp
 
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])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp

print((max+K)/2)

Submission status: Accepted

Solution code:
import numpy as np

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

tmp = np.sum(p[:K])
max = tmp
for i in range(N-K):
    tmp = tmp-p[i]+p[i+K]
    if tmp>max:
        max = tmp

print((max+K)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[0]
def ex(A):
  return (1+A)/2.0
for i in range(N):
  Q.append(ex(P[i]))
Q=np.array(Q)
R=Q.cumsum()
ans=0
for i in range(K,N+1):
  S=R[i]-R[i-K]
  if ans<S:
    ans=S
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
lis = [0]*N
for i in range(N):
    if p[i]%2 == 1:
        lis[i] = p[i]//2+1
    else:
        lis[i] = (p[i]+1)/2
ans = sum(lis[:K])
temp = sum(lis[:K])
for j in range(N-K):
    temp -= lis[j]
    temp += lis[j+K]
    if temp > ans:
        ans = temp
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
cums = [0]*1001
cnt = 0
for i in range(1001):
    cnt += i
    cums[i] = cnt

p_new = [cums[j]/j for j in P]
sp = sum(p_new[0:K])

ans = []
ans.append(sp)
cnt = 0
for k in range(K,N):
    sp = sp + p_new[k]
    sp = sp - p_new[cnt]
    cnt += 1
    ans.append(sp)

print(max(ans))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = [int(i) for i in input().split()]
P = []
P_S = [0]
ans_list = []
temp = 0

for i in range(N):
    P.append((p[i] + 1)/2)
    temp = temp + P[i]
    P_S.append(temp)
for i in range(K,N+1):
    ans_list.append(P_S[i] - P_S[i - K])

print(max(ans_list))

Submission status: Accepted

Solution code:
#D - Dice in Line
#一つのサイコロふったときに出る目の期待値は(面の数+1)/2
n,k=list(map(int,input().split()))
dices = list(map(float,input().split()))
expected = []
answer = 0
i = 0
j = 0
sumOfValue = 0
expected.append(i)
#サイコロの目を期待値に変換して累積和のリスト作る
for eyes in dices:
    i = (eyes+1)/2
    j = j + i
    expected.append(j)
#最大値を求める
for t in range(n-k+1):
    sumOfValue = expected[t+k] - expected[t]
    if(answer <= sumOfValue):
        answer = sumOfValue
print(answer)

Submission status: Accepted

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

print(max(ans))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
su=[0]
for i in range(N):
    p[i]=((p[i]+1)/2)
    su.append(su[i]+p[i])
ans=0
for i in range(K,N+1):
    ans=max(ans,su[i]-su[i-K])
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]+1)/2)
su=[0]
for i in range(N):
    su.append(su[i]+p[i])
ans=0
for i in range(K,N+1):
    ans=max(ans,su[i]-su[i-K])
print(ans)

Submission status: Accepted

Solution code:
def dice_in_line():
    N,K=map(int,input().split())
    p_n=list(map(int,input().split()))
    max=x=sum(p_n[:K])
    for i in range(N-K):
        x+=(p_n[K+i]-p_n[i])
        if max<x:
            max=x
    print((max+K)/2)

dice_in_line()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc154/tasks/abc154_d

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

# 初期値として0~Kのサイコロの目を最大値として保持しておく
max = x = sum(s[:K])
for i in range(N - K):
    x += (s[K + i] - s[i])
    if max < x:
        max = x

# 期待値はサイコロの目の数の合計+1*サイコロの数/2
print((max + K) / 2)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
t=list(input().split())
s=[int(n) for n in t]
max=x=sum(s[:K])
for i in range(N-K):
    x+=(s[K+i]-s[i])
    if max<x :
        max=x
print((max+K)/2)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    pi = list(map(int, input().split()))
    kitai = [(x + 1) * 0.5 for x in pi]
    kitai_acc = [0]  # acc[i] = sum(kitai[0:i])
    for i in range(n):
        kitai_acc.append(kitai_acc[-1] + kitai[i])
    res = 0
    for i in range(n + 1 - k):
        x = kitai_acc[i + k] - kitai_acc[i]
        res = max(res, x)
    print(res)

main()

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
ex = [i + 1 for i in p]
ans = sum(ex[0: K])
max_ans = ans
for i in range(K, N):
    ans += ex[i] - ex[i - K]
    max_ans = max(ans, max_ans)
print(max_ans / 2.0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = list(map(int,input().split()))

x = [(e + 1) / 2 for e in c]

t = sum(x[0:b])
res = t
for i in range(a - b):
  t -= x[i]
  t += x[i+b]
  res = max(res,t)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    l= sys.stdin.readline()
    N, K = map(int, l.split())
    
    l = sys.stdin.readline()
    nums = list(map(lambda a:(int(a)+1)/2.0, l.split()))
    
    M = sum(nums[:K])
    mx = M
    for i in range(K, len(nums)):
        #print(nums[i-K], nums[i])
        M = M - nums[i-K] + nums[i]

        if M > mx:
            mx = M
        
    return mx
if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
p_array = list(map(int,input().split()))

sum_max = sum(p_array[:K])
now_sum = sum_max
for i in range(1,N-K+1):
    now_sum -= p_array[i-1]
    now_sum += p_array[i+K-1]
    if now_sum > sum_max:
        sum_max = now_sum
    # print(now_sum)
print((K+sum_max)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
lp=list(map(int,input().split()))
maxsum=sum(lp[:K])
befsum=maxsum
for i in range(1,N-K+1):
    tmpsum=befsum-lp[i-1]+lp[i+K-1]
    if tmpsum>maxsum:
        maxsum=tmpsum
    befsum=tmpsum
print((maxsum+K)/2)

Submission status: Accepted

Solution code:
def main():

    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    # print(exp_sum(n, k, P))
    mx = 0
    for i in range(k):
        mx += (P[i] + 1) / 2
    tmp = mx
    for i in range(k, n):
        tmp += (P[i] - P[i - k]) / 2
        mx = max(mx, tmp)
    print(mx)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0
for i in range(k):
    ans += 1/2*(2+(seq[i]-1)) 
score = ans
for i in range(n-k):
  score -= 1/2*(2+(seq[i]-1)) 
  score += 1/2*(2+(seq[i+k]-1)) 
  ans = max(ans, score)
  
print(round(ans, 9))

Submission status: Accepted

Solution code:
from itertools import accumulate
n,k=map(int,input().split())
a=list(map(int, input().split()))
b = [0] + a
b = list(accumulate(b))

ans = []
for i in range(n-k+1):
    ans.append(b[i+k]-b[i])
index = ans.index(max(ans))
a=a[index:index+k]
total=0
for i in a:
  total+=(1+i)/2
print(total)

Submission status: Accepted

Solution code:
r=input().strip().split()
N=int(r[0])
a=int(r[1])
z=input().strip().split()
s=0
for p in range (a):
    s+=(1+int(z[p]))/2
maximum=s

for j in range (0,N-a):
  s-=(1+int(z[j]))/2
  s+=(1+int(z[j+a]))/2
  if s>maximum:
    maximum=s

print(maximum)

Submission status: Accepted

Solution code:
import itertools as it
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

s = list(it.accumulate(p))
ss = [s[k-1]]
for i in range(k, n):
    ss.append(s[i] - s[i-k])
    
ans = max(ss)
print((ans+k)/2)

Submission status: Accepted

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

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

ans = 0
cumlative = []
for i in range(N):
	if i == 0:
		cumlative.append(ave[i])
	else:
		cumlative.append(cumlative[i-1]+ave[i])
	#print(ave[i:K+i])
if N == K:
	ans = cumlative[N-1]
else:
	for i in range(N-K):
		ans = max(cumlative[i+K] - cumlative[i],ans)

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
n, k = map(int, input().split())
p = deque(map(int, input().split()))

adjacent = deque()
for i in range(k):
    adjacent.append(p.pop())

ans = sum(adjacent)
count = ans

while p:
    pp = p.pop()
    count -= adjacent.popleft()
    count += pp
    adjacent.append(pp)
    ans = max(ans, count)

print((ans + k) / 2)

Submission status: Accepted

Solution code:
from collections import deque
n, k = map(int, input().split())
p = deque(map(int, input().split()))

adjacent = deque()
for i in range(k):
    adjacent.append(p.popleft())

ans = sum(adjacent)
count = ans

while p:
    pp = p.popleft()
    count -= adjacent.popleft()
    count += pp
    adjacent.append(pp)
    ans = max(ans, count)

print((ans + k) / 2)

Submission status: Accepted

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

ruisekiwa=[0]

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

max_value=0
for i in range(N-K+1):
    tmp=ruisekiwa[i+K]- ruisekiwa[i]
    if(max_value < tmp):
        max_value=tmp
print(max_value)

Submission status: Accepted

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

S=[0]
for i in range(n):
   S.append(S[i]+P[i])
ans=0
for j in range(n-k+1):
   ans=max(ans,(S[j+k]-S[j]))

print((ans+k)/2)

Submission status: Accepted

Solution code:
N,K = list(map(int,input().strip().split()))
P = list(map(int,input().strip().split()))
def find(P,K):
    temp = 0
    MAX = 0
    for i in range(K):
        temp += (P[i]+1)/2
    MAX = max(MAX,temp)
    for i in range(K,len(P)):
        temp -= (P[i-K]+1)/2
        temp += (P[i]+1)/2
        MAX = max(MAX,temp)
    return MAX
print(find(P,K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n,k = map(int,input().split())
ans = 0
a = list(map(int,input().split()))
a = [0] + a
b = list(accumulate(a))
for i in range(n-k+1):
    ans = max(ans,b[i+k]-b[i])
print((ans+k)/2)

Submission status: Accepted

Solution code:
# numpy使うときは、PyPyは不可
import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)

# ans = 0
#
# for num in range(len(P)):
#     tmp = P[num:num+K].sum()
#     if ans < tmp:
#         ans = tmp
#
# print(ans/2)


# 回答
Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

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

Submission status: Accepted

Solution code:
# numpy使うときは、PyPyは不可
import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)

"""
ans = 0

for num in range(len(p)):
    tmp = p[num:num+K].sum()
    if ans < tmp:
        ans = tmp

print(float(ans))

"""

# 回答
Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

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

Submission status: Accepted

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

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

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

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

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

print(ans*0.5 + k*0.5)

Submission status: Accepted

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

cum_E = [0] * (N+1)
for i in range(N):
  cum_E[i+1] = cum_E[i] + (A[i]+1)/2
  
k_cum_E = [0] * (N-K+1)
for i in range(N-K+1):
  k_cum_E[i] = cum_E[i+K] - cum_E[i]

print(max(k_cum_E))

Submission status: Accepted

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

ev = [0] * n

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

cs = [0] * n
cs[0] = ev[0]

for i in range(1,n):
    cs[i] = cs[i-1] + ev[i]

ans = cs[k-1]

for i in range(n-k):
    s = cs[i+k] - cs[i]
    if s > ans:
        ans = s

print(ans)

Submission status: Accepted

Solution code:
total, tar = list(map(int, input().split()))
dice_array = list(map(int, input().split()))

hope_array = [0.0] * total
for i in range(total):
   hope_array[i] = (dice_array[i] * (dice_array[i] + 1)) / 2 / dice_array[i]

dice_total = [0]
 
for i in range(total):
  dice_total.append(hope_array[i] + dice_total[i])
 
ans = dice_total[tar]
tar_num = tar
for i in range(total - tar):
  tmp = dice_total[i + 1 + tar] - dice_total[i + 1]
  if ans < tmp:
    ans = tmp

print(ans)

Submission status: Accepted

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

*e, = map(lambda x: (x*(x+1)//2)/x, p)

cusum = [0]*(n+1)
for i in range(n):
    cusum[i+1] = cusum[i]+e[i]

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

print(ans)

Submission status: Accepted

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

sum_K = [0]*(N-K+1)
sum_K[0] = sum(nums[:K])
for pos in range(1,N-K+1):
    sum_K[pos] = sum_K[pos-1] -   \
        nums[pos-1] + nums[pos+K-1]

print((max(sum_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-1):
    p[i+1]=p[i+1]+p[i]
max=p[K-1]
if N>K:
    for i in range(1,N-K+1):
        tmp=p[i+K-1]-p[i-1]
        if max < tmp:
            max=tmp
print((max+K)/2.)

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

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

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

Submission status: Accepted

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

INDEX = 0
total = 0
for i in range(K):
    total += P[i]

tmp = total
for i in range(N - K):
    tmp = tmp - P[i] + P[i + K]
    
    if tmp > total:
        total = tmp
        INDEX = i+1


# MA = 0
# for i in range(N - K + 1):
#     M = 0
#     for j in range(K):
#         M += P[i + j]
    
#     if M > MA:
#         MA = M
#         INDEX = i

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

cumsum = np.cumsum(exp_val)

for i in range(k-1, n):
    if i==k-1:
        val = cumsum[i]
    else:
        val = max(val, cumsum[i] - cumsum[i-k])
print(val)

Submission status: Accepted

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

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

cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(cur, max_mean)

print(max_mean)

Submission status: Accepted

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

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

cur = max_mean
for l in range(k, n):
    cur += 0.5 * (p[l] - p[l-k])
    max_mean = max(max_mean, cur)

print(max_mean)

Submission status: Accepted

Solution code:
from itertools import accumulate
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
P = [int(_) for _ in stdin.readline().rstrip().split()]
evs = [(1+p)/2 for p in P]
evs = [0] + list(accumulate(evs))
ans = 0
for i in range(K, N+1):
    ans = max(ans, evs[i]-evs[i-K])
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read

n, k, *p = map(int, read().split())
tmp = sum(p[:k])
res = tmp
for i in range(k, n):
  tmp = tmp - p[i - k] + p[i]
  if tmp > res:
    res = tmp
print((res + k) / 2)

Submission status: Accepted

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

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

ans=0
for j in range(N-K+1):
  if j==0:
    tmp = sum(p[0:K])
  else:
    tmp = tmp - p[j-1] + p[j+K-1]
  
  if ans < tmp:
    ans = tmp

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]
accum_expect=[0]+list(np.cumsum(e_list))

n=N-K+1
expect_list=[accum_expect[i+K]-accum_expect[i] for i in range(0,n)]

print(max(expect_list))

Submission status: Accepted

Solution code:
from itertools import*
n,k,*p=map(int,open(0).read().split())
q=[0]+list(accumulate([(x+1)/2 for x in p]))
print(max(q[i+k]-q[i] for i in range(n-k+1)))

Submission status: Accepted

Solution code:
n, k = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
e = [(1 + p[i]) * 0.5 for i in range(n)]
s = 0.0
for i in e[:k]:
    s += i
t = s
for i in range(n - k):
    t = t - e[i] + e[k + i]
    s = max(s, t)
print(s)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=[int(x) for x in input().split()]
#さいころの出目の和を集計
for i in range(n):
    p[i]+=1

sdict={}
sdict[0]=p[0]

for i in range(n-1):
	sdict[i+1]=sdict[i]+p[i+1]
j=0
ans=0
if n!=k:
	while (j+k <n):
		dif=sdict[j+k]-sdict[j]
		ans=max(dif,ans)
		j+=1
else:
	ans=sum(p)
print(ans/2)

Submission status: Accepted

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

cnt=0
for i in range(k):
    cnt+=p[i]
ans=cnt
for j in range(k,n):
    cnt=cnt-p[j-k]+p[j]
    ans=max(cnt,ans)


print('{:.20f}'.format((ans+k)/2))

Submission status: Accepted

Solution code:
A = list(map(int , input().split()))
B = list(map(int , input().split()))
kitaiti =[(i+1)/2 for i in B]
ans = []
dd = [0]
for i in range(A[0]):
    dd.append(dd[i] + kitaiti[i])
for i in range(A[1] , A[0]+1):
    ans.append(dd[i] - dd[i - A[1]])
print(max(ans))

Submission status: Accepted

Solution code:
from sys import stdin


def get_result(data):
    N, K = data[0]
    A = data[1]
    e_val = [(1 + val) / 2 for val in A]

    # 累積和を算出 (最初は0)
    e_cumsum = [0]
    for i in range(N):
      e_cumsum.append(e_cumsum[i] + e_val[i])

    # 隣接するK個の部分和を取得
    e_sum_k = []
    for i in range(N+1-K):
      e_sum_k.append(e_cumsum[i+K] - e_cumsum[i])

    return max(e_sum_k)

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
plist = map(int, raw_input().split())

exp_list = [(p + 1) / 2.0 for p in plist]
ans = s = sum(exp_list[:k])
for i in xrange(n - k):
    s = s - exp_list[i] + exp_list[i + k]
    ans = max(ans, s)

print ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
e = []
s = [0]
sj = []

for x in p:
    e.append((1 + x) / 2)

for x in range(n):
    s.append(s[x] + e[x])

for x in range(k, n + 1):
    sj.append(s[x] - s[x - k])
    
print(max(sj))

Submission status: Accepted

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

def calculate_Expectation(n):
    n = int(n)
    p = 1/n
    e = p * (n*(n+1)/2)
    return e

E = list(map(calculate_Expectation, input().split()))
if N == K:
    print(sum(E))
else:
    S = [0]
    for i, e in enumerate(E):
        S.append(S[i]+e)

    sum_of_E = []
    for left in range(1, N+1-K):
        right = left + K
        sum_of_E.append(S[right]-S[left])
    print(max(sum_of_E))

Submission status: Accepted

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

Submission status: Accepted

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

tmp = sum(pi[0 : K])
max = tmp

if N == K:
    print((max + K) / 2)
else:
    for i in range(N - K):
        tmp = tmp - pi[i] + pi[i + K]
        if tmp > max:
            max = tmp
    print((max + K) / 2)

Submission status: Accepted

Solution code:
from collections import deque

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

def f(num) :
    return (num*(num+1) / 2) / num

for i, a in enumerate(A) :
    A[i] = f(a)

res = 0
tmp = 0

for i, a in enumerate(A) :
    if i < k :
        tmp += a
        res += a
    else :
        tmp += a
        tmp -= A[i-k]
        res = max(res, tmp)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

a = []
#各サイコロの期待値のリストaを作成
for i in range(N):
  a.append((p[i]+1)/2)
#累積和のリストSの作成
S = [0]
for i in range(N):
  S.append(S[i]+a[i])
#隣接N個のサイコロの期待値の和のリストansの作成
ans = []
for i in range(N-K+1):
  ans.append(S[i+K]-S[i])
  
print(max(ans))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
s = [0]
ans = [0]

#累積和
for i in range(n):
    s.append(s[i]+(p[i]+1)/2)

#区間kの和をリストに格納
for i in range(n-k+1):
    ans[i] = s[k+i] - s[i]
    ans.append(ans[i])

#区間kの和の中で最大値
print(max(ans))

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
p_seq = np.array(list(map(int, input().split())))
e_seq = (p_seq + 1) / 2
s_seq = [0]
for e in e_seq:
    s_seq.append(s_seq[-1] + e)
print(max(s_seq[i + k] - s_seq[i] for i in range(n - k + 1)))