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_l = list(map(int,input().split()))

expected = []
for val in p_l:
    expected.append((val+1)/2)

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

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

print(ans)

Submission status: Accepted

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

pref_sum = [None]* (N+1)
pref_sum[0] = 0
pref_sum[1] = (l[0]+ 1) / 2

for i in range(1, N):
    t = (l[i]+ 1) / 2
    pref_sum[i+1] = t + pref_sum[i]

ans = -float("inf")

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


print(ans)

Submission status: Accepted

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

pref_sum = [None]* (N+1)
pref_sum[0] = 0
pref_sum[1] = (1/l[0]) * ((l[0] * (l[0]+ 1)) / 2)

for i in range(1, N):
    t = (1/l[i]) * ((l[i] * (l[i]+ 1)) / 2)
    pref_sum[i+1] = t + pref_sum[i]

ans = -float("inf")

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


print(ans)

Submission status: Accepted

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

S = sum(p[:K])
S_MAX = S

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

E = (S_MAX + K)/2

print(E)

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:
from itertools import accumulate
n, k = map(int, input().split())
P= list(map(int, input().split()))
e = [(1+p) / 2 for p in P]
ps =[0] + list(accumulate(e))
a = 0
for i in range(n+1- k):
    if a < ps[i+k] - ps[i]:
        a = ps[i+k] - ps[i]

print(a)

Submission status: Accepted

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

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

print('{:.10f}'.format(ans/2))

Submission status: Accepted

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

Submission status: Accepted

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

memory = {}

def expectation(x):
    if x in memory:
        return memory[x]
    else:
        return x * (1 + x) / (2 * x)

def solve(N: int, K: int, P: "List[int]"):
    largest = 0
    if K == 1:
        largest = expectation(max(P))
        print(largest)
        return

    for i, p in enumerate(P[:-K+1]):
        if i == 0:
            summation = 0
            for k in range(K):
                summation += expectation(P[i + k])
            if summation > largest:
                largest = summation
        else:
            summation -= expectation(P[i-1])
            summation += expectation(P[i + K - 1])
            if summation > largest:
                largest = summation

    print(largest)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
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:
N, K = map(int, input().split())
P = list(map(int, input().split()))
max_p = max(P)
dp = [0] * (max_p + 1)
dp[1] = 1
for i in range(2, max_p + 1):
    dp[i] = dp[i - 1] + 0.5
S = 0
for j in range(K):
    S += dp[P[j]]
ans = S
for i in range(1, N - K + 1):
    S = S - dp[P[i - 1]] + dp[P[i + K - 1]]
    ans = max(ans, S)
print(ans)

Submission status: Accepted

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

def exp(x):
    return (1+x)/2

import numpy as np
cums=np.cumsum([0] + [exp(i) for i in p])

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

print(ans)

Submission status: Accepted

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

def exp(x):
    return (1+x)/2

total=sum([exp(i) for i in p[:k]])
ans=total
bk=ans
for i in range(1, n-k+1):
    start=i-1
    end=start+k
    total=bk-exp(p[start])+exp(p[end])
    ans=max(ans, total)
    bk=total
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    ps = list(map(int, input().split()))
    e = [(1+p)/2 for p in ps]

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

#print(ans)
print(max(ans))

Submission status: Accepted

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

from itertools import accumulate
E = [(1+p)/2 for p in P]
ES = list(accumulate(E))

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

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]+1)/2)
ans = 0
for i in range(N-K+1):
    tmp = S[i+K] - S[i]
    ans = max(ans, tmp)
print('{:.20f}'.format(ans))

Submission status: Accepted

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

E = [(1 + p) / 2 for p in p]
curr_sum = sum(E[:K])
curr_max = curr_sum

for i in range(N - K):
    curr_sum += (E[i + K] - E[i])
    curr_max = max(curr_max, curr_sum)

print(curr_max)

Submission status: Accepted

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

sum_ans = sum([(i+1)/2 for i in P[0:K]])
result = [sum_ans]
for i in range(K,N):
    result.append(result[-1] + (P[i]+1)/2 - (P[i-K]+1)/2)

print(max(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    Ep = [(x+1)/2 for x in p]


    base = sum(Ep[:K])
    ans = base
    for i in range(N-K):
        base -= Ep[i]
        base += Ep[i+K]
        ans = max(ans, base)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(result)

Submission status: Accepted

Solution code:
def main():
    #input
    N,K=map(int,input().strip().split())
    P=list(map(int,input().strip().split()))
    
    #期待値行列
    E=list(map(lambda x:(x+1)*x//2/x,P))
    S=[0 for n in range(N-K+1)]
    for n in range(K):
        S[0]+=E[n]
    
    ans=S[0]
    for i in range(1,N-K+1):
        S[i]=S[i-1]-E[i-1]+E[i+K-1]
        ans=max(ans,S[i])
    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

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

for i in range(len(A)-K+1):
    if i == 0:
        t = sum(A[i:i+K])
    else:
        t -= A[i-1]
        t+= A[i+K-1]
    ans = max(ans,t)

print((ans+K)/2)

Submission status: Accepted

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

#期待値の累積和
S = [0]*(n+1)
for i in range(1, n+1):
    S[i] = S[i-1]+P[i-1]

ans = max([S[x]-S[x-k] for x in range(k,n+1)])
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
P = list(map(int,input().split()))
check = [0]*1001
tmp_p = []
for p in P:
    if check[p]!=0:
        tmp_p.append(check[p])
    else:
        tmp = ((1+p)*p/2)/p #期待値の計算
        tmp_p.append(tmp)
ans = sum(tmp_p[0:k])
tmp_ans = ans
for i in range(n-k):
    tmp_ans += (tmp_p[k+i]-tmp_p[i])
    ans = max(ans, tmp_ans)
print(ans)

Submission status: Accepted

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

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

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

if n == 1:
    print(l[0])
else:
    lans = [ls[i+k]-ls[i] for i in range(len(ls)-k)]
    print(max(lans))

Submission status: Accepted

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

lis = list()

p = [(i + 1)/2 for i in p ]
numpy.set_printoptions(precision=16)

cumSum = numpy.cumsum(p)

cumSum2 = list(cumSum)

cumSum2.insert(0,0)

for i in range(0, N-K+1):
    lis.append(cumSum2[K+i] - cumSum2[i])

print('{:.12f}'.format(max(lis)))

Submission status: Accepted

Solution code:
import sys
import numpy as np

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, K = map(int, input().split())
    p = np.array(list(map(int, input().split())), dtype='f8')
    p = (p + 1) / 2
    rs = np.zeros(N + 1, dtype='f8')
    for i in range(N):
        rs[i + 1] = rs[i] + p[i]
    ans = 0
    for i in range(N - K + 1):
        ans = max(ans, rs[i + K] - rs[i])

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)
#print(C)
M = 0
for i in range(n - k + 1):
    #print(C[i + k],C[i])
    M = max(M, C[i + k] - C[i])

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
P = list(map(int, input().split()))
E = [0, ]
tot = 0
for i in range(n):
    tot += P[i] * (P[i] + 1) / (2 * P[i])
    E.append(tot)
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 itertools
N,K=map(int,input().split())
B=list(map(int,input().split()))
C=[0]+list(itertools.accumulate([(x+1)/2 for x in B]))

D=max(C[i]-C[i-K] for i in range(K,N+1))
print(D)

Submission status: Accepted

Solution code:
import itertools

N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [(p+1)/2 for p in P]
A = list(itertools.accumulate(Q))
A = [0] + A
mx = 0
for i in range(N-K+1):
    mx = max(mx, A[i+K]-A[i])
print(mx)

Submission status: Accepted

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


# ruisekiwa
ruiseki = [0] * (n+1)

for i, x in enumerate(ary):
    ruiseki[i+1] = ruiseki[i] + x

kmax = 0
for i in range(n+1-k):
    ksum = ruiseki[i+k] - ruiseki[i]
    kmax = max(kmax, ksum)

print((kmax+k) / 2)

Submission status: Accepted

Solution code:
from collections import deque

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

p_l = list(map(int, input().split())) 
p_sum_k_l = []

q = deque([])
first_sum = 0
for i in range(k):
    ex = (p_l[i]+1)/2
    q.append(ex)
    first_sum += ex

p_sum_k_l.append(first_sum)
# print(q)

for i in range(k, len(p_l)):
    # print('---')
    poped = q.popleft()
    added = (p_l[i]+1)/2
    # print(poped, added)
    diff = added-poped
    # print(diff)
    next_sum = p_sum_k_l[-1] + diff
    p_sum_k_l.append(next_sum)
    q.append(added)

print(max(p_sum_k_l))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(N+1-K):
    T.append(S[i+K]-S[i])

print(max(T))

Submission status: Accepted

Solution code:
from collections import deque
n,k = map(int,input().split())
p = list(map(int,input().split()))
s = deque()
s.append(0)
tot = 0
for i in p:
    tot += i
    s.append(tot)

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

print((top+k)/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
a = list(map(lambda p_i: (p_i+1)/2, p))
ans = sum(a[:K])
m = sum(a[:K])

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

print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

E = [0 for i in range(N+1)]
for i in range(N):
    E[i+1] = E[i] + (P[i] + 1) / 2
    
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 itertools as iter

def main():
    n, k = list(map(int, input().split()))
    p = [0]
    p.extend(list(iter.accumulate([(1+int(x))/2 for x in input().split()])))
    #print(p)
    
    s = []
    for i in range(n-k+1):
        s.append(p[i+k]-p[i])
    #print(s)
    print(max(s))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
p = [int(i) for i in input().split()]

expected = []
for i in range(N):
    expected.append((p[i]+1)/2)
m = [0] + list(accumulate(expected))
ans = 0
for i in range(1, len(m)-K+1):
    ans = max(ans, m[i+K-1] - m[i-1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

for j in range(N-K):
    if total>=now-(P[j]+1)/2+(P[j+K]+1)/2:
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
    else:
        total=now-(P[j]+1)/2+(P[j+K]+1)/2
        now=now-(P[j]+1)/2+(P[j+K]+1)/2
print("{:.8f}".format(total))

Submission status: Accepted

Solution code:
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N,K = MI()
P = LI()
temp = 0
for i,v in enumerate(P):
    if i < K-1:
        temp += v
    elif i== K-1:
        temp += v
        ans = temp
    else:
        temp -= P[i-K]
        temp += v
        ans = max(ans,temp)
ans = (ans+K)/2
print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n, k = map(int, input().split())
    from itertools import accumulate
    A = list(map(int, input().split()))
    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成
    num=0
    val=0
    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    for i in range(k, n + 1):
        if B[i]-B[i-k]>val:
            val=B[i]-B[i-k]
            num=i

    ans = 0
    for j in A[num-k:num]:
        ans += (0.5 * j * (1 + j)) / j
    print(ans)
resolve()

Submission status: Accepted

Solution code:
#154D
def main():
    import sys
    N, K =map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    #期待値の計算
    #print(P)
    P = list(map(lambda x:((x*(x+1)//2)/x), P))
    #print(P)
    #累積和
    for i in range(N-1):
        P[i+1] +=P[i]
    #print(P)
    ans = P[K-1]
    for i in range(N-K):
        ans = max(ans, P[K+i]-P[i])
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def E(x):
    return (x*(x+1)//2)/x
def main():
    N, K = map(int, readline().split())
    e = [E(int(i)) for i in readline().split()]
    s = [0.]
    for i in range(N):
        s.append(s[i]+e[i])
    ans = 0.
    for i in range(N-K+1):
        ans = max(s[K+i]-s[i], ans)
    print('{:.12f}'.format(ans))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ps = list(map(int, input().split()))
es = [(p+1)/2 for p in ps]
rs = []
s = sum(es[0:K])
rs.append(s)
for i in range(N-K):
  s = s-es[i]+es[i+K]
  rs.append(s)
#print(rs)
r = max(rs)
print(r)

Submission status: Accepted

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

Es = [(1+p_i)/2 for p_i in p]

t = sum(Es[0:k])
ans = t

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

print(ans)

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

part=e[0:k]
kari=sum(part)
ans=kari
for i in range(n-k):
  kari+=e[i+k]
  kari-=e[i]
  if kari>ans:
    ans=kari
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
P = list(map(int, input().split()))
ExP = list(map(lambda x: (x+1)/2, P))
ans = 0
prev = 0

#for i = 0
now = sum(ExP[0: k])
#print(0, now)
ans = max(ans, now)
prev = now

for i in range(1, n-k+1):
    now = prev - ExP[i-1] + ExP[i+k-1]
#    print(i, now)
    ans = max(ans, now)
    prev = now
print(ans)

Submission status: Accepted

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


exp = [0 for i in range(n+1)]

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

ans = 0
for i in range(k, n+1):
    ans = max(ans, exp[i] - exp[i-k])
print("{:.12f}".format(ans))

Submission status: Accepted

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

def expect(p):
  return (p + 1) / 2

l = [0 for i in range(n+1)]
for i in range(1, n+1):
  l[i] = expect(p[i-1]) + l[i-1]

ans = 0
for i in range(k, n+1):
  ans = max(ans, l[i] - l[i-k])
print("{:.12f}".format(ans))

Submission status: Accepted

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

sum_p =[0]
tmp = 0
for i in p:
    tmp += i
    sum_p.append(tmp)

max_expect = 0
for i in range(k, n+1):
    tmp = sum_p[i] - sum_p[i - k]
    max_expect = max(tmp, max_expect)

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

Submission status: Accepted

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

awk = 0
aix = k - 1
for i in range(k):
  awk += a[i]
a_max = awk

for i in range(k,n):
  awk = awk + a[i] - a[i-k]
  if a_max < awk:
    a_max =  awk
    aix   = i

ans = 0.0
#print('aix={}'.format(aix))
for i in range(aix-k+1,aix+1 ):
  #print(a[i])
  ans += ( 1 + a[i] )  / 2.0

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from decimal import Decimal

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

if N==1:
    print((p.max() + 1) / Decimal(2))
elif N==K:
    print((p.sum() + K) / Decimal(2))
else:
    p = np.cumsum(p)

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

    ans = (max(ans) + K) / Decimal(2)

    print(ans)

Submission status: Accepted

Solution code:
#154d
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
e_list = [(1 + p) / 2 for p in p_list]
max_v = sum(e_list[:k])
ret = max_v
#print(e_list, e_list[:k])
for i in range(n - k):
  calc = ret - e_list[i] + e_list[i + k]
  max_v = max(max_v, calc)
  ret = calc
  #print(ret, e_list[i], e_list[i + k], calc)
print(max_v)

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ll = [l[k - 1]] + [j - i for i, j in zip(l, l[k:])]
    ans = max(ll)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ll = [l[k - 1]] + [l[i + k] - l[i] for i in range(n-k)]
    ans = max(ll)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ans = l[k - 1]
    for i in range(0, n - k):
        x = l[i + k] - l[i]
        ans = max(ans, x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from copy import deepcopy

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

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


max_sum = 0
temp_sum = 0

#最初の一組目を計算
for j in range(k):
    temp_sum += ((p[j] + 1) * p[j] / 2) / p[j]

if n == k:
    max_sum = temp_sum
    print(max_sum)

else:
    #2組目以降を計算
    for i in range(1,n-k+1):
        temp_sum = temp_sum - ((p[i-1] + 1) * p[i-1] / 2) / p[i-1] + ((p[i+k-1] + 1) * p[i+k-1] / 2) / p[i+k-1]

        if temp_sum > max_sum:
            max_sum = temp_sum


    print(max_sum)




#n,k = map(int,input().split())
#
#p = list(map(int,input().split()))
#
#max_sum = 0#for j in range(k):
#    result += ((p[max_where + j] + 1) * p[max_where + j] / 2) / p[max_where + j]
#max_where = 0
#
##pi ~ pi+2の合計が最大のものが期待値も最大になる。
#for i in range(0,n-k+1):
#    temp_sum = sum(p[i:i+k])
#    if temp_sum > max_sum:
#        max_sum = temp_sum
#        max_where = i
#
#result = 0
#

#
#print(result)

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
s = [0]
for i in range(n):
  if i==0:
    s.append(p[0])
  else:
    s.append(s[-1]+p[i])
pmax = 0
for i in range(n-k+1):
  if s[i+k]-s[i]>pmax:
    pmax = s[i+k]-s[i]
print(pmax)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
R = [0]*(N+1)
ans = 0
for i in range(1,N+1):
    X = p[i-1]
    R[i] = R[i-1] + (X*(X+1))/2/X
    if i+1 >= K:
        ans = max(ans,R[i]-R[i-K])

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

def main():
  n,k=map(int,input().split())
  p=list(map(lambda x:(1+int(x))/2,input().split()))
  sumk=sum(p[:k])
  ans=sumk
  for i in range(n-k):
    sumk-=p[i]
    sumk+=p[i+k]
    ans=max(ans,sumk)
  print(ans)
if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())

Submission status: Accepted

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

aves = [(i + 1) / 2 for i in P]
max_ave = sum(aves[0:K])
temp = max_ave
for i in range(N - K):
    temp -= aves[i]
    temp += aves[i + K]
    if temp > max_ave:
        max_ave = temp
print(max_ave)

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n,k = readInts()
p = readInts()

s = []
s.append((p[0]+1)/2)

for i in range(1,n):
	s.append(s[-1]+(p[i]+1)/2)

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

print(ans)