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())
a=[int(s) for s in input().split()]
b=[0]*k
c=0
v=[0]*n
v[0]=a[0]
for i in range(n-1):
    v[i+1]=v[i]+a[i+1]
mx=v[k-1]
for i in range(k,n):
    g=v[i]-v[i-k]
    mx=max(mx,g)  
    
print((mx+k)/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
E = [0] * N
for i in range(N):
    P = 0.5 * p[i] * (p[i] + 1)
    E[i] = P / p[i]
S = sum(E[:K])
s = S
for i in range(N - K):
    s -= E[i]
    s += E[i + K]
    S = max(S, s)
print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
gki = sum(a[0:k])
tmp = gki
rng = k
for i in range(k,n):
  tmp = tmp-a[i-k]+a[i]
  if tmp>gki:
    gki = tmp
    rng = i+1
  
E = 0
for i in a[rng-k:rng]:
  E += (i+1)/2
print(E)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
pn = list(map(int, input().split()))
ex_list = [(pn[i]+1)/2 for i in range(len(pn))]
ex_wa_list = []
wa = 0
for i in range(len(ex_list)):
    wa += ex_list[i]
    ex_wa_list.append(wa)
Ans_list = []
wa2 = 0
for i in range(n-k+1):
    if i == 0:
        wa2 = ex_wa_list[k-1]
    else:
        wa2 = ex_wa_list[k-1+i] - ex_wa_list[i-1]
    Ans_list.append(wa2)
print(max(Ans_list))

Submission status: Accepted

Solution code:
import sys


def resolve(in_):
    N, K = map(int, next(in_).split())
    A = map(int, next(in_).split())
    number_plus1 = list(i + 1 for i in A)

    v = [0] * N
    v[0] = sum(number_plus1[:K])
    for i, (before, after) in enumerate(zip(number_plus1, number_plus1[K:]), 1):
        v[i] = v[i - 1] - before + after

    expected = max(v) / 2

    return expected


def main():
    answer = resolve(sys.stdin.buffer)
    print(f'{answer:.12f}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, k = inintm()
P = inintl()

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

for i in range(n):
    s[i+1] = s[i]+(1 + (P[i]-1)*0.5)

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

print(ans)

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
P = [int(x) for x in sys.stdin.readline().rstrip().split()]


# 目が 1 ... p のときの期待値
def kitaichi(p):
    return (p + 1) / 2

goukei = 0
for i in range(K):
    goukei += kitaichi(P[i])

gmax = goukei
for i in range(N - K):
    goukei = goukei + kitaichi(P[K + i]) - kitaichi(P[i])  # 次の区間の合計
    gmax = max(goukei, gmax)

print(gmax)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = [(i + 1) / 2 for i in p]
now = ans = sum(l[:k])

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

print(ans)

Submission status: Accepted

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

a = [0] * (N - K + 1)
a[0] = sum(P[:K])
for i in range(1, N - K + 1):
    a[i] = a[i - 1] - P[i - 1] + P[i + K - 1]
    
print((max(a) + K) / 2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[None]*(n-k+1)
a[0]=sum(p[0:k])
for i in range(1,n-k+1):
    a[i]=a[i-1]-p[i-1]+p[i+k-1]
b=max(a)
c=(b/2)+(0.5*k)
print(c)

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def ev(n):
    return 0.5*(n+1)


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

    p_ev = list(map(ev, p))

    s = np.cumsum(p_ev)
    s = np.insert(s, 0, 0)

    ans = []

    for i in range(n - k+1):
        ans.append(s[i + k] - s[i])

    print(max(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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(((1+p[i])*p[i]/2)/p[i])

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

ans = 0
for i in range(K,len(s)):
    ans = max(ans,s[i]-s[i-K])

if N == K:
    print(max(s))
else:
    print(ans)

Submission status: Accepted

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

p = list(map(lambda x: (1+x)/2, p))
s = [0]
num = 0
for i in range(n):
  num += p[i]
  s.append(num)
l = []
for i in range(n - k + 1):
  l.append(s[i+k]-s[i])

print(max(l))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
P = list(map(lambda x:int(x)+1, input().split()))
# accumulate
A = [0] + list(accumulate(P))
#print(A)
res = 0
for i in range(n-k+1):
    res = max(res, A[i+k] - A[i])
print(res/2.0)

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(((1+p[i])*(p[i]/2))/p[i])

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

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

if N == K:
    print(max(que))
else:
    print(ans)

Submission status: Accepted

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

for p in P:
    E.append(p*(p+1)/(2*p))

cumsumE = [0]
for e in E:
    cumsumE.append(cumsumE[-1] + e)

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

Submission status: Accepted

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

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

#print(dice)
ans = 0
prev = sum(dice[:K])
ans = prev
for i in range(K,N):
  temp = prev-dice[i-K]+dice[i]
  ans = max(ans,temp)
  prev = temp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
P2 = [(((P[i]+1)) / 2) for i in range(N)]
# i番目は1~P[i]の値を出す
# P[i]が大きいものからK個選んで期待値を求める
# 幅が最大のところを見つける
s = 0
init = 0
for i in range(K):
    s += P2[i] 
tmp = s
for i in range(1, N-K+1):
    tmp = tmp - P2[i-1] + P2[i+K-1]
    if s < tmp:
        s = tmp
        init = i

print(s)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
expectation = list(map(lambda x: (x+1) / 2, map(int, input().split())))
cur_expectation = sum(expectation[:K])
max_expectation = cur_expectation
for i in range(N - K):
    cur_expectation -= expectation[i]
    cur_expectation += expectation[i + K]
    if cur_expectation > max_expectation:
        max_expectation = cur_expectation
print(max_expectation)

Submission status: Accepted

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

PMAX = 1000
s = [0] * (PMAX + 1)
for i in range(PMAX):
    s[i+1] = s[i] + (i + 1)

e = [0] * (N + 1)
for i, p in enumerate(P):
    e[i+1] = e[i] + (s[p] / p)

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

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split())
a = np.array([int(x) for x in input().split()])
val=sum(a[:K])
max_val=val
for i in range(N-K):
  val+=a[K+i]
  val-=a[i]
  max_val=max(val,max_val)
print(max_val/2+K*0.5)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
expected = []
cumsum = []
for x in arr:
	sum = (x * (x + 1)) // 2
	ex = sum / x
	expected.append(ex)

sum = 0
maxi = 0
taken = 0
bad = 0
for x in expected:
	sum += x
	taken += 1
	if taken == k:
		 maxi = max(maxi, sum)
	elif taken > k:
		sum -= expected[bad]
		bad += 1
		maxi = max(maxi, sum)
print(maxi)

Submission status: Accepted

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    P = list(map(int, input().split()))
    total = 0
    ans = 0
    for i in range(N):
        if i < K:
            total += (P[i]+1)/2
            if i == K-1:
                ans = max(ans, total)
        else:
            total -= (P[i-K]+1)/2
            total += (P[i]+1)/2
            ans = max(ans, total)
    print(ans)
        

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

s=0
for i in range(k):
    s += P[i]

ms=s
for i in range(len(P)-k):
    s +=(P[i+k]-P[i])
    if s>ms :
        ms=s

print( (ms+k)/2)

Submission status: Accepted

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

s = 0
e = k
t = sum(p[0:k])

ans = 0
while True:
    ans = max(ans, t)
    if e == n:
        break
    t -= p[s]
    t += p[e]
    s += 1
    e += 1

print(ans / 2)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
L=[]
M=[0]
c=0
m=0
x=0
for i in range(200100):
    c+=i
    L.append(c)
for i in P:
    m+=L[i]/i
    M.append(m)
if N!=K:
    for i in range(N-K+1):
        x=max(M[K+i]-M[i],x)
else:
    x=M[K]-M[0]
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

rwa = [0]*(len(p)+1)

for i in range(len(rwa)-1):
    rwa[i+1] = rwa[i]+p[i]

wa = [0]*(N-K+1)
for i in range(len(wa)):
    wa[i] = rwa[K+i]-rwa[i]

t = wa.index(max(wa))

re = 0
for i in range(K):
    if p[t+i]%2 == 0:
        re += p[t+i]/2 +0.5
    else:
        re += p[t+i]//2 +1


print(re)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

exlis = []


for i in lis:
    a = (1+i)/2
    exlis.append(a)


nlis = list(itertools.accumulate(exlis))


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

print(ans)

Submission status: Accepted

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

c = sum(exp[:k])
cmax = c

for i in range(n-k):
    c -= exp[i]
    c += exp[i+k]

    if c > cmax:
        cmax = c

print(cmax)

Submission status: Accepted

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

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

a = [0] * N
a[0] = l[0]
for i in range(1,len(l)):
    a[i] = a[i-1] + l[i]

ans = 0
for i in range(K,len(l)):
    ans = max(ans,a[i]-a[i-K])

if N - K == 0:
    print(max(a))
else:
    print(ans)

Submission status: Accepted

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

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

a = [0] * N
a[0] = l[0]
for i in range(1,len(l)):
    a[i] = a[i-1] + l[i]

ans = 0
for i in range(K,len(l)):
    ans = max(ans,a[i]-a[i-K])

if N == 1 or N - K == 0:
    print(max(a))
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

a=[0]+list(itertools.accumulate(a))
ans=0

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

Submission status: Accepted

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

#logging.debug("デバッグスタート") #
l = [[] for i in range(n)]#期待値
m = [[] for i in range(n - k + 1)]  #k個の合計

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

#logging.debug("l = {}".format(l))#
m[0] = sum(l[0:k])
ans = m[0]

for i in range(1, n - k + 1):
    #logging.debug("m[i-1] = {} ,l[i-1] = {} ,l[i+k] = {}".format(m[i - 1], l[i - 1], l[i + k - 1]))  #
    m[i] = m[i - 1] - l[i - 1] + l[i + k - 1]
    if m[i] > ans:
        ans = m[i]

#logging.debug(m)#
print(ans)

Submission status: Accepted

Solution code:
nn, kk = list(map(int,input().split()))
pp = list(map(int,input().split()))

expectation = [0]*(nn-kk+1)
expectation[0] = sum(pp[0:kk])

for i in range(1,nn-kk+1):
    expectation[i] = expectation[i-1] - pp[i-1] + pp[i+kk-1]

print((max(expectation)+kk)/2)

Submission status: Accepted

Solution code:
import sys


def main():
    input = sys.stdin.buffer.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    N,K = [int(i) for i in input().split()]
    P = [int(i) for i in input().split()]
    prev_K_sum = max_K_sum = sum(P[:K])
    start = 0
    for i in range(N-K):
        cur_K_sum = prev_K_sum - P[i] + P[i+K]
        if cur_K_sum > max_K_sum:
            start = i + 1
            max_K_sum = cur_K_sum
        prev_K_sum = cur_K_sum
    target = P[start:start+K]
    ans = sum([(num+1)/2.0 for num in target])
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[]
for i in range(n):
    exp=(p[i]+1)/2
    l.append(exp)
cumsum=[0]+list(itertools.accumulate(l))
ans=0
for i in range(n-k+1):
    sum_num=cumsum[i+k]-cumsum[i]
    if sum_num>ans:
        ans=sum_num
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
from itertools import accumulate
acc=[0]+list(accumulate(P))
print((max(b-a for a,b in zip(acc,acc[K:]))+K)/2)

Submission status: Accepted

Solution code:

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

cur = sum((X[i] + 1) / 2 for i in range(K))
ans = cur
for i in range(K, N):
    cur += (X[i] + 1) / 2 - (X[i - K] + 1) / 2
    ans = max(ans, cur)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
memo = [0] * 200001 
def kitaichi(kazu):
    global memo
    ans = 0
    if memo[kazu] == 0:
        for i in range(1,kazu+1):
            ans += i * (1 / kazu)
        memo[kazu] = ans
    return memo[kazu]

n,k = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
max_p = 0
for j in range(k):
    ans += kitaichi(p[j])
#print(ans)
max_p = ans
for i in range(n-k):
    #print(ans,kitaichi(p[i+k]),kitaichi(p[i]))
    ans = ans + kitaichi(p[i+k]) - kitaichi(p[i])
    #print(ans)
    max_p = max(ans,max_p)
print(max_p)

Submission status: Accepted

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

import numpy as np

Q = np.cumsum(P)

R = np.pad(Q,K,'constant', constant_values=0)[:N]

a = np.argmax(Q-R)

ans = 0
for i in range(K):
    ans += (1.00+P[a-i])/2.00
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

pos = 0
n = m = sum(P[0:K])
for i in range(1,N):
    if i+K > N:
        break
    n = n - P[i-1] + P[K-1+i]
    if n > m:
        pos = i
        m = n

print((sum(P[pos:pos+K]) + K) / 2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
maxi=0
suml=sum(l[:k])
maxl=sum(l[:k])
for i in range(n-k):
    if suml-l[i]+l[k+i]>maxl:
        maxl=suml-l[i]+l[k+i]
        maxi=i+1
    suml=suml-l[i]+l[k+i]
sumsum=0
for j in range(maxi,maxi+k):
    sumsum+=(l[j]+1)/2
print(sumsum)

Submission status: Accepted

Solution code:
def main():
    """"ここに今までのコード"""
    N, K = map(int, input().split())
    dice_list = list(map(int, input().split()))
    max, s = 0, 0

    for i in range(K):
        s += (dice_list[i] + 1) / 2
    
    max = s

    for i in range(N-K):
        s -= (dice_list[i] + 1) / 2
        s += (dice_list[i+K] + 1) / 2
        if s > max:
            max = s
    
    print(max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N, K = LI()
    P = LI()

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,k = inpm()
P = inpl()

ave = []
for p in P:
    ave.append((p+1)/2)
    
pre = sum(ave[:k])
ans = pre
for i in range(1,n-k+1):
    now = pre - ave[i - 1] + ave[i + k - 1]
    pre = now
    ans = max(ans,now)

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
from itertools import accumulate
acc=[0]
acc.extend(accumulate(P))
ans=0
for i in range(N-K+1):
  exp=(acc[K+i]-acc[i]+K)/2
  ans=max(exp,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

jj = 0
koho=[]
for i in range(K):
    jj+=arr[i]
    koho.append(jj)

for i in range(N-K):
    jj+=arr[i+K]
    jj-=arr[i]
    koho.append(jj)

a=max(koho)
print(a/2+(K/2))

Submission status: Accepted

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

ksum = [0 for _ in range(N-K+1)]
ksum[0] = sum(p[:K])
for i in range(N-K):
    ksum[i+1] = ksum[i] - p[i] + p[i+K]

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0] + list(accumulate(P))
print((max(b - a for a, b in zip(acc, acc[K:])) + K) / 2)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0] + list(accumulate(P))
ans = 0
for a, b in zip(acc, acc[K:]):
  exp = (b - a + K) / 2
  ans = max(exp, ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools
n, k = (int(i) for i in input().split())
P = [int(i) for i in input().split()]

probs = list(itertools.accumulate([(1+p)/2 for p in P]))
probs.insert(0,0)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    P = [int(x) for x in input().split()]
    p_e = list()
    exp = 0
    for p in P:
        # 期待値
        # 累積和
        exp += (1+p)/2
        p_e.append(exp)
    # 初期値
    maxv = p_e[k-1] - 0
    for i in range(1, n-k):
        # 隣接するk個の期待値の和
        p_sum = p_e[k+i] - p_e[i]
        maxv = max(maxv, p_sum)
    print(maxv)
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()))

xs = [0] + list(accumulate(map(lambda v: (1 + v) * v // 2 / v, p)))
ans = 0
for i in range(n - k + 1):
    ans = max(ans, xs[i + k] - xs[i])
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
P = [int(x) for x in input().split()]
p_e = list()
exp = 0
for p in P:
    # 期待値
    # 累積和
    exp += (1+p)/2
    p_e.append(exp)  
# この後差を取るので
# n==kの時とそうでない時でやり方を分けないとだめ
if n == k:
    print(p_e[-1])
else:
    # 初期値
    maxv = p_e[k-1] - 0
    for i in range(1, n-k):
        # 隣接するk個の期待値の和
        p_sum = p_e[k+i] - p_e[i]
        maxv = max(maxv, p_sum)
    print(maxv)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    P = [int(x) for x in input().split()]
    p_e = list()
    exp = 0
    #p_e.append(exp)
    # for p in P:
    #     exp += (1+p)/2
    #     p_e.append(exp)
    # maxv = p_e[k] - p_e[0]
    # for i in range(1, n-k+1):
    #     p_sum = p_e[k+i] - p_e[i]
    #     maxv = max(maxv, p_sum)
    # print(maxv)
    for p in P:
        # 期待値
        # 累積和
        exp += (1+p)/2
        p_e.append(exp)  
    if n == k:
        print(p_e[-1])
    else:
        # 初期値
        maxv = p_e[k-1] - 0
        for i in range(1, n-k):
            # 隣接するk個の期待値の和
            p_sum = p_e[k+i] - p_e[i]
            maxv = max(maxv, p_sum)
        print(maxv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    P = [int(x) for x in input().split()]
    p_e = list()
    exp = 0
    p_e.append(exp)
    for p in P:
        exp += (1+p)/2
        p_e.append(exp)
    maxv = p_e[k] - p_e[0]
    for i in range(1, n-k+1):
        p_sum = p_e[k+i] - p_e[i]
        maxv = max(maxv, p_sum)
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    P = [int(x) for x in input().split()]
    p_e = list()
    exp = 0
    for p in P:
        # 期待値
        # 累積和
        exp += (1+p)/2
        p_e.append(exp)  
    if n == k:
        print(p_e[-1])
    else:
        # 初期値
        maxv = p_e[k-1] - p_e[0]
        for i in range(1, n-k):
            # 隣接するk個の期待値の和
            p_sum = p_e[k+i] - p_e[i]
            maxv = max(maxv, p_sum)
        print(maxv)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 期待値:マス目の総和／マス目の数, マス目の最大値+最小値[1]／2
l = [(i+1)/2 for i in l] # 期待値に変換

# 累積和を取得
from itertools import accumulate
cum = [0] + list(accumulate(l))

# 差分を考慮しつつ k個の和をリストする → 最大値が ans
sum_k = []
for j in range(n-k+1):
    sum_k.append(cum[k+j] - cum[j])

print(max(sum_k))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
X=[]
for a in P:
    X.append(a/2+0.5)
gou=sum(X[0:K])

han=-32
saigou=sum(X[N-K:N])
han=saigou
for a in range(N-K-1):

    if gou>han:
        han=gou
    gou=gou-X[a]+X[a+K]

print(han)

Submission status: Accepted

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

Submission status: Accepted

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

#累積和を使う
e_s = [0] * (N+1)
for i in range(N):
    # 期待値の計算
    e = (p[i]+1)/2
    e_s[i+1] = e_s[i] + e

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

Submission status: Accepted

Solution code:
from itertools import accumulate

n, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))
print((max(a[i + k] - a[i] for i in range(n - k + 1)) + k) / 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-07-29 16:20:16 +0900
# LastModified: 2020-07-29 16:30:22 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from itertools import accumulate


def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    s = [(x+1)/2 for x in p]
#    print(s)
    s = list(accumulate(s))
    s.insert(0, 0)
    ans = 0
#    print(s)
    for i in range(n-k+1):
        ans = max(ans, s[i+k]-s[i])
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

# サイコロ（1...p）の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
    cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
    temp = cum_sum[i + K - 1] - cum_sum[i - 1]
    # print(temp)
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
import collections

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

# サイコロ（1...p）の期待値は(1+p)/2
cum_sum = [0]
for i in range(0, N):
    cum_sum.append(cum_sum[i] + (1 + p[i]) / 2)
# print(cum_sum)
# 調べる区間は[1,...,K],...,[N-K+1,...N]
ans = 0
for i in range(1, N - K + 2):
    temp = cum_sum[i + K - 1] - cum_sum[i - 1]
    # print(temp)
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
import copy

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

s = sum(p[:k])
smax = copy.deepcopy(s)
for i in range(n-k):
    s += p[i+k] - p[i]
    smax = max(smax, s)

print((smax+k)/2)

Submission status: Accepted

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

def calcExpectedValue(prob):
  return (prob+1)/2

def solve(n,k,p):
  expLst = [calcExpectedValue(prob) for prob in p]
  cum = [0]*(n+1)
  for i in range(n):
    cum[i+1] = cum[i] + expLst[i]
  ans = 0
  i = 0
  while i+k <= n:
    ans = max(ans,cum[i+k]-cum[i])
    i += 1
  return ans




def main():
  N,K = map(int,input().split())
  p = list(map(int,input().split()))
  print(solve(N,K,p))
  return

if __name__ == '__main__':
  main()