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

e = [0] * 1001
e[1] = 1.0
for i in range(2, 1001):
    e[i] = e[i-1] + 0.5

ans = [0] * (n-k+1)
for i in range(k):
    ans[0] += e[p[i]]
for i, v in enumerate(range(k, n), start=1):
    ans[i] = ans[i-1] + e[p[v]] - e[p[v-k]]
print(max(ans))

Submission status: Accepted

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

# estP = [-1]
def est(i):
    return 1.0 + (i - 1) * 0.5
# for i in range(1, 1001):
# print(i, sum([j * 1.0 / i for j in range(1, i + 1)]))
# estP.append(sum([j * 1.0 / i for j in range(1, i + 1)]))
# print(i, 1.0 + (i - 1) * 0.5)
# # print(estP)

# 普通に計算する
# - 2x10e5 の2重ループなのでTLE

# m = -1.0
# for i in range(N - K + 1):
#     vi = sum([est(P[j]) for j in range(i, i + K)])
#     m = max(vi, m)
# print(m)


# かしこい計算: 累積和
# WAになってしまった
# sumA = [est(P[0])]
# for i in range(1, N):
#     sumA.append(sumA[-1] + est(P[i]))
# # print([est(P[i]) for i in range(N)])
# # print(sumA)

# m = -1
# for i in range(N - K):
#     # print(i, i + K, sumA[i + K] - sumA[i])
#     m = max(m, sumA[i + K] - sumA[i])
# print(m)

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

# 0 ~ K-1 の期待値
ans = sum(expected[:K])
tmp = ans
for i in range(N - K):
    # 新しく追加 (i番目を抜いて，i+K番目を入れる，横に移動)
    tmp = tmp + expected[i + K] - expected[i]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

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

# ans[i] = iを含めてk個前までの期待値の総和
ans = [0 for i in range(n)]
ans[k-1] = sum(p[0:k])
for i in range(k,n) :
  ans[i] = ans[i-1] + p[i] - p[i-k]
  
print(max(ans))

Submission status: Accepted

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

answer = sum(pp[:k])
total = sum(pp[:k])

for i in range(n-k):
    total = total - pp[i] + pp[i+k]
    answer = max(answer, total)

print((answer+k)/2)

Submission status: Accepted

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

Submission status: Accepted

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

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

print((ans + k) / 2)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

#n面サイコロの出る目の期待値
def n_mean(n):
  return 0.5*(n+1)

Pmean=list(map(lambda x: n_mean(x), P))
Psum=[0]*N
Psum[0]=Pmean[0]
for i in range(1,N):
  Psum[i]=Psum[i-1]+Pmean[i]
#print(Psum)
ans=0
for i in range(N-K+1):
  if i==0:
    ans=Psum[K-1]
  else:
    #1~6 
    ans=max(ans, (Psum[i+K-1]-Psum[i-1]))
  
print(ans)

Submission status: Accepted

Solution code:
#累積和の利用！！！！！！！！
from itertools import accumulate
n,k = map(int,input().split())
p = list(map(int,input().split()))

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

ans = []
for i in range(n-k+1):
    ans.append(m[i+k] - m[i])
    
print(max(ans))

Submission status: Accepted

Solution code:
nk=input().rstrip().split(" ")
n=int(nk[0])
k=int(nk[1])
numbers=input().rstrip().split(" ")
sigmas=[0]
sigma=0
for i in range(n):
    sigma=sigma+(int(numbers[i])+1)/2
    sigmas.append(sigma)
#print(sigmas)
deltas=[]
for i in range(n-k+1):
    delta=sigmas[k+i]-sigmas[i]
    deltas.append(delta)
#print(deltas)
answer=0
for delt in deltas:
    if delt>=answer:
        answer=delt
print(answer)

Submission status: Accepted

Solution code:


def submit():
    n, k = map(int, input().split())
    plist = list(map(int, input().split()))
    
    # 各iのサイコロの出目の期待値を計算
    exp = {1: 1}
    max_p = max(plist)
    for x in range(2, max_p + 1):
        exp[x] = exp[x - 1] + x
    for x in range(1, max_p + 1):
        exp[x] /= x
    
    # 期待値リストに変換し、合計が最大値になるところを探す
    explist = [exp[p] for p in plist]
    curr_sum = sum([e for e in explist[:k]])
    curr_max = curr_sum

    l, r = 1, k
    while r < n:
        curr_sum += explist[r] - explist[l - 1]
        if curr_sum > curr_max:
            curr_max = curr_sum
        l += 1
        r += 1

    print(curr_max)
    

if __name__ == "__main__":
    submit()

Submission status: Accepted

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

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

sum_ = sum(kobetu_kitaiti[0:K])
max_ = sum_

for i in range(N-K):
    sum_ = sum_ - kobetu_kitaiti[i] + kobetu_kitaiti[i+K]
    max_ = max(sum_, max_)

#print(kobetu_kitaiti)
print(max_)

Submission status: Accepted

Solution code:
from itertools import accumulate    # 累積和: list(accumulate(num_list))

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

    compute_list = []

    for num in num_list:
        compute_list.append((1+num)/2)

    sum_list = list(accumulate(compute_list))

    if k == n:
        print(sum_list[k-1])
        exit()

    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

s.append(sum)

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

m = max(s)/2 + k/2

print(m)

Submission status: Accepted

Solution code:

def sum_ari_seq(a):
    return a * (a + 1) // 2


def mean(a):
    return sum_ari_seq(a) / a


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

max_value = 0
for i in range(k):
    max_value += mean(p[i])

cur = max_value
for i in range(k, n):
    cur += (mean(p[i]) - mean(p[i-k]))
    max_value = max(max_value, cur)

print(max_value)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

q = []

for value in p:
    q.append((value + 1) / 2)

sm = [sum(q[:K])]
for i in range(1, N-K+1):
    sm.append(sm[-1] - q[i-1] + q[i+K-1])

print(max(sm))

Submission status: Accepted

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

    cur = sum(P[:k])
    #print('first ', cur)
    ans = cur

    for i in range(1, n-k+1):
        cur += P[i+k-1] - P[i-1]
        if cur < ans: continue
        ans = cur

    print(ans)
__main()

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [0] + p
m = (np.array(p) + 1)/2
m[0] = 0
cum  = np.cumsum(m)

ma = 0
for i in range(n - k + 1):
    a = cum[i + k] - cum[i]
    if ma < a:
        ma = a
print(ma)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
l = list(map(int, input().split()))
l2 = [0 for _ in range(n+1)]
for i in range(n):
  l[i] = 1+l[i]
for i in range(n):
  l2[i + 1] = l2[i]+l[i]
l3 = []
for i in range(n-k+1):
  l3.append(l2[i+k]-l2[i])
print("{:.8}".format(max(l3)/2))

Submission status: Accepted

Solution code:
from math import fsum
s = [0] * 1001
for i in range(1, len(s)):
    s[i] = s[i - 1] + i
N, K = map(int, input().split())
exps = [s[p] / p for p in map(int, input().split())]
exp = fsum(exps[:K])
ans = exp
for i in range(K, N):
    exp = fsum((exp, -exps[i - K], exps[i]))
    if ans < exp:
        ans = exp
print(ans)

Submission status: Accepted

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

ans=0
tmp=0
tmp2=sum(s[0:k])
kukan=[0,n]
for i in range(n-k):
    tmp2 -= s[i]
    tmp2 += s[k+i]
    if tmp < tmp2:
        tmp = tmp2
        kukan = [i+1,i+k+1]

for i in range(kukan[0],kukan[1]):
    ans += (s[i]+1)/2
    
print(ans)

Submission status: Accepted

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

pp_ex = list(map(lambda p: (p + 1) / 2, pp))

max_ex = 0
for i in range(k):
    max_ex += pp_ex[i]
bef_ex = max_ex
for i in range(1, n - k + 1):
    ex = bef_ex - pp_ex[i - 1] + pp_ex[i + k - 1]
    bef_ex = ex
    if max_ex < ex:
        max_ex = ex

print(max_ex)

Submission status: Accepted

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


def solve(N: int, K: int, p: "List[int]"):
    p2 = [(i + 1) / 2 for i in p]
    l = []
    for i in range(N - (K - 1)):
        if i == 0:
            s = 0
            for j in range(K):
                s += p2[j]
            l.append(s)
        else:
            l.append(l[-1] - p2[i - 1] + p2[i + (K - 1)])
    print(max(l))
    # m = -1
    # for i in range(N - (K - 1)):
    #     s = 0
    #     for j in range(K):
    #         s += p2[i + j]
    #     m = max(m, s)
    # print(m)


# Generated by 1.1.6 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())
dice = list(map(int,input().split()))

dice_cumsum = [0]*(n+1)

for i in range(1,n+1):
    dice_cumsum[i] = dice_cumsum[i-1] + dice[i-1]
    
max_n = 0
max_i = 0
for i in range(n-k+1):
    sum_dice = dice_cumsum[k+i] - dice_cumsum[i]
    if sum_dice > max_n:
        max_n = sum_dice
        max_i = i

sum_odds = 0
for i in range(k):
    sum_odds += (dice[max_i+i]-1)*0.5+1

print(sum_odds)

Submission status: Accepted

Solution code:
def main():
    
    n,k = map(int, input().split())
    
    p_list = list(map(int, input().split()))
 
    #p_list.sort(reverse=True)
    #print(p_list)
 
    ans = 0
    if k == 1:
        p_list.sort(reverse=True)
        ans = (p_list[0]+1)*0.5
    else:
        for j in range(n-(k-1)):
            if j == 0:
                ans_tmp = 0
                for i in range(k):
                    ans_tmp += (p_list[i+j]+1)*0.5
            else:
                ans_tmp -= (p_list[(j-1)]+1)*0.5
                ans_tmp += (p_list[k+(j-1)]+1)*0.5
            
            
            if ans_tmp >= ans:
                ans = ans_tmp
 
    print(ans)
 
    
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

n, k = na()
p = na()
s = 0
for i in range(k):
    s += 1/p[i] * (1/2) * (1 + p[i]) * p[i]
ans = s
l = 0
r = k
for i in range(n-k):
    #print(l, r)
    s -= 1/p[l] * (1/2) * (1 + p[l]) * p[l]
    s += 1/p[r] * (1/2) * (1 + p[r]) * p[r]
    ans = max(ans, s)
    l += 1
    r += 1
print(ans)

Submission status: Accepted

Solution code:
M=[]
for i in range(1001):
   m=(i+1)/2
   M.append(m) 

N,K=map(int,input().split())
P=list(map(int,input().split()))
S=[]
s=0
for i in range(N):
    a=P[i]
    s=s+M[a]
    S.append(s)
Q=[]
Q.append(S[K-1])
q=0
for i in range(N-K):
    q=S[i+K]-S[i] 
    Q.append(q)
    q=0
print(max(Q))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=input().split()
P=[int(z) for z in p]
hopes=[(1+a)/2 for a in P]
S=sum(hopes[:K])
answers=[S]
for a in range(1,N-K+1):
    S=S+hopes[a+K-1]-hopes[a-1]
    answers.append(S)
print(max(answers))

Submission status: Accepted

Solution code:
import time
start = time.time()

n, k = map(int, input().split())
p = list(map(int, input().split()))
# p = [i for i in range(1, n+1)]
ans = 0
# for i in range(n-k+1):
#     exp = 0
#     for j in range(k):
#         exp += (p[i+j] * (p[i+j] + 1)) / 2 / p[i+j]
#     if exp > ans:
#         ans = exp
total = [0] * n
for i in range(n):
    if i == 0:
        total[i] = p[i]
    else:
        total[i] = total[i-1] + p[i]
maxi_sum = 0
maxi_num = 0
for i in range(k-1, n):
    if i == k-1:
        maxi_sum = total[i]
        maxi_num = i
    else:
        if total[i] - total[i-k] > maxi_sum:
            maxi_sum = total[i] - total[i-k]
            maxi_num = i
# print(maxi_sum, maxi_num)
ans = 0
for i in range(maxi_num - k + 1, maxi_num + 1):
    ans += (p[i] * (p[i] + 1)) / 2 / p[i]
print(ans)

# print(time.time() - start)

Submission status: Accepted

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

for i in range(k, n+1):
    cost = cs[i] - cs[i-k]
    # print(cs[i], cs[i-k])
    if ans < cost:
        ans = cost
# print(cs, ev)
print(ans)

Submission status: Accepted

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

ans = 0
cost = sum(ev[:k])
for i in range(k, n+1):
    if ans < cost:
        ans = cost
    if i == n:
        continue
    cost -= ev[i-k]
    cost += ev[i]
    # print(i)

print(ans)
# print(ev)

Submission status: Accepted

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

E = [0] * N

for i, p in enumerate(P):
  E[i] = (1 + p) * p / 2 / p
  
# 初期化  
sum_exp = sum(E[0:K])
max_exp = sum_exp

for head, e in enumerate(E[K:], 0):
  sum_exp = sum_exp - E[head] + e
  max_exp = max(max_exp, sum_exp)
  
print(max_exp)

Submission status: Accepted

Solution code:
# D - Dice in Line

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

S = [0]

for i in range(N):
    S.append(S[i]+P[i])

ans = 0

for j in range(K, N+1):
    if S[j]-S[j-K]>ans:
        ans = S[j]-S[j-K]

print(0.5*(K+ans))

Submission status: Accepted

Solution code:
# D - Dice in Line

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

S = [0] * (N+1)

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

ans = 0

for j in range(K, N+1):
    if S[j]-S[j-K]>ans:
        ans = S[j]-S[j-K]

print(0.5*(K+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()]

D = sum(P[:K])
index = 0
ans = D

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

Submission status: Accepted

Solution code:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
P = [(int(x) + 1) / 2 for x in stdin.readline().rstrip().split()]

D = sum(P[:K])
index = 0
ans = D

for i in range(1, N - K + 1):
    if D + P[i + K - 1] - P[i - 1] > ans:
        ans = D + P[i + K - 1] - P[i - 1]
    D = D + P[i + K - 1] - P[i - 1]
print(ans)

Submission status: Accepted

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

#各サイコロの期待値算出
exp_value_list = list()
for i in range(N):
    exp_value_list.append(((p_list[i])+1)/2)

#初項の期待値算出
ans = 0
for i in range(K):
    ans += exp_value_list[i]

#1個ずつずらして、最大値を求める。
selected = ans
for i in range(0,N-K):
    selected -= exp_value_list[i]
    selected += exp_value_list[i+K]
    ans = max(ans,selected)
    
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
d = list(map(int, input().split(" ")))
w = [0]*(len(d)+1)

# 累積和の計算
w[0] = 0
for i in range(0, len(d)):
  w[i+1] = w[i] + d[i]
  
ans = 0
for i in range(0, a-b+1):
    ans = max([ans,w[i+b]-w[i]])

d2 = 0.5*b + ans/2

if a == 1:
  print((d[0]+1)/2)
else:
  print(d2)

Submission status: Accepted

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

a=[]
ans=0
f=0
for i in range(k):
  f+=g(p[i])
a.append(f)
ans=f
for i in range(n-k):
  a.append(a[i]+g(p[k+i])-g(p[i]))
  ans=max(ans,a[i+1])
  
print(ans)

Submission status: Accepted

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

sum_tmp = sum(a[:k])
sum_max = sum_tmp
for i in range(k,len(a)):
    sum_tmp += a[i] - a[i-k]
    if sum_tmp > sum_max:
        sum_max = sum_tmp
print((sum_max + k)/2)

Submission status: Accepted

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

asum = [p[0]]
for i in range(1, N, 1):
	asum.append(asum[i - 1] + p[i])

tsum = [asum[K - 1]]
for i in range(K, N, 1):
	tsum.append(asum[i] - asum[i - K])

print(max(tsum))

Submission status: Accepted

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

p_e = [0] + [ (x + 1) * 0.5 for x in p]
p_p = [0]

for i in range(1, n+1):
    p_p.append(p_p[i-1] + p_e[i])

e_sum = [p_p[i] - p_p[i - k] for i in range(k, n+1)]
print(max(e_sum))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
s = list(map(int, input().split()))
ans = [0]*N
sum
for i in range(0, K):
    ans[i] = (s[i]+1)/2
sum = sum(ans)
mx = sum
for i in range(K, N):
    ans[i] = (s[i]+1)/2
    sum = sum+ans[i]-ans[i-K]
    if mx < sum:
        mx = sum
# print(s, ans, mx)
print(mx)

Submission status: Accepted

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


def expected(n):
    return (1+n)/2


p=list(map(expected,p))

for i in range(K):
    maxexp+=p[i]
now=maxexp
for i in range(N-K):
    now=now+p[i+K]-p[i]
    maxexp=max(now,maxexp)
print(maxexp)

Submission status: Accepted

Solution code:
from decimal import Decimal

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

cur = sum(p[:k])
res = cur

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

d = Decimal(res.numerator) / Decimal(2*res.denominator)
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
all_num, select_num = map(int, input().split())
dice = [int(a) for a in input().split()]

for i in range(all_num - (select_num - 1)):
    if i == 0:
        max_sum = this_sum = sum(dice[i:(i + select_num)])
    else:
        this_sum = this_sum - dice[i - 1] + dice[i + select_num - 1]

        if this_sum > max_sum:
            max_sum = this_sum

print((max_sum + select_num) * 0.5)

Submission status: Accepted

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

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

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
total = sum(p[:K])
ans = total
for j in range(N-K):
  total = total+p[K+j]-p[j]
  ans = max(ans,total)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = list(map(int, input().split()))
lst2 = []
for i in lst:
  lst2.append((i*(i+1)//2)/i)
ans = sum(lst2[:M])
max_ans = ans
num = 0
for i in range(M, N):
  ans = ans - lst2[num] + lst2[i]
  num += 1
  if ans > max_ans:
    max_ans = ans
print(max_ans)

Submission status: Accepted

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

Submission status: Accepted

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

p_mean = [(i+1)/2 for i in p]

p_ruikei = [0] * n
p_ruikei[0] =  p_mean[0]

for i in range(1, n):
    p_ruikei[i] = p_ruikei[i-1] + p_mean[i]

maxx = p_ruikei[k-1]
for i in range(1, n-k+1):
    mean = p_ruikei[i+k-1] - p_ruikei[i-1]

    if mean > maxx:
        maxx = mean

print(maxx)

Submission status: Accepted

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

pi = [0 for _ in range(n)]
si = [0 for _ in range(n)]

pi = [int(s) for s in input().split()]
pi = [(1+s)/2 for s in pi]

si[0] = pi[0]
for i in range(1,n):
    si[i] = si[i-1] + pi[i]

#print(pi)
#print(si)
#print(si[2]-si[0])

ans = 0
if not (n==k):
    for i in range(n-k):
        ans = max(si[i+k]-si[i],ans)
else:
    ans = si[n-1]

print(float(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_list = list(map(lambda x: (1 + int(x)) / 2, input().split()))
csum_list = [0]
sum = 0
for p in p_list:
    sum += p
    csum_list.append(sum)
now_max = 0
for i in range(n - k + 1):
    tmp = csum_list[i + k] - csum_list[i]
    if tmp > now_max:
        now_max = tmp
print(now_max)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
#最後にdecimal にして2で割る
p = list(map(lambda x :x+1,p))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = sum(p[:k])/2 + k/2
s = ans

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

Submission status: Accepted

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

def main():
    N, K = map(int, input().split())
    p = list(map(lambda x: (1 + int(x)) / 2, input().split()))

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

# 期待値は(1+P)/2 https://rikeilabo.com/sum-formula-of-numerical-sequence
# 累積和を求めておく．隣接するK個の和はS_{j+K} - S_j
# 期待値の前計算→累積和の計算→隣接するK項の和の計算 (１乗オーダー)
E_list = []
for dice in dices:
    E_list.append((1 + dice) * 0.5)

S_list = []  # i番目までのサイコロの期待値の累積和
for i in range(len(dices)):
    # S_list.append(sum(E_list[:i + 1]))  # アホ
    S_list.append(E_list[0] if i == 0 else S_list[i - 1] + E_list[i])

print(max(list(S_list[j + K] - S_list[j] for j in range(len(dices) - K))) if len(dices) != K else S_list[-1])

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
dice_list = [int(i) for i in input().split()]
wa_list = [0]
for dice in dice_list :
    # prob = 0
    # for i in range(dice) :
    #     prob += (i+1) * (1/(dice))
    prob = (1+dice) / 2
    wa_list.append(wa_list[-1] + prob)

max_p = -1
for i in range(N-K+1) :
    p = wa_list[i+K] - wa_list[i]
    if (max_p < p) :
        max_p = p

print(max_p)

Submission status: Accepted

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

left = 0
right = k - 1
maxi = sum(P[left: right + 1])
now = maxi
for i in range(n - k):
    if now - P[i] + P[i + k] > maxi:
        left = i + 1
        right = i + k
        maxi = now - P[i] + P[i + k]
    now = now - P[i] + P[i + k]

kitai = []
for i in range(1001):
    if i == 0:
        kitai.append(0)
    else:
        kitai.append((1 + i)/ 2)

ans = 0
for p in P[left: right + 1]:
    ans += kitai[p]
print(ans)

Submission status: Accepted

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

def sm(lst, j, k):
  return lst[j+k]-lst[j]

def max(lst, k):
  sumlst = [0]
  for i in range(len(lst)):
    sumlst.append(sumlst[i]+lst[i])
  res = 0
  for i in range(N-k+1):
    if res < sm(sumlst, i, k):
      res = sm(sumlst, i, k)
  res = (res+k)/2
  return res

print(max(List, K))

Submission status: Accepted

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

print((ans+K)/2)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    
    i = list(map(int, input().split()))
    N = i[0]
    K = i[1]
    
    p = list(map(int, sys.stdin.readline().split()))
    max_s = 0
    s_current = 0
    
    for i in range(N - K + 1):
        if i == 0:
            p_list = p[:K]
            max_s = sum(p_list)
            s_current = max_s
        else:
            s_current = s_current - p[i - 1] + p[i + K - 1]
            if s_current > max_s:
                max_s = s_current
        
    ans = (max_s + K) / 2.0
    print(ans)

Submission status: Accepted

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

e_max = 0
e_prev = 0

for i in range(n - k + 1):
    e = 0
    if i == 0:
        for j in range(k):
            e += p[i + j]
    else:
        e = e_prev - p[i-1] + p[i+k-1]
    if e > e_max:
        e_max = e
    e_prev = e

r = e_max/2 + (0.5 * k)
print(str(r))

Submission status: Accepted

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

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
  if i!=0:
    e[i]+=e[i-1]

arr=[]

if n==k:
  print(e[-1])
  exit()

for i in range(k,n):
  s=i-k
  arr.append(e[i]-e[s])

print(max(arr))

Submission status: Accepted

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

for i in range(k):
    e[0] += float(1/2 * (1 + p[i]))
for j in range(n-k):
    e[j+1] = e[j] + float(1/2 * (p[j+k]-p[j]))
print(max(e))

Submission status: Accepted

Solution code:
#abc154 d
n,k=map(int,input().split())
p=list(map(int,input().split()))
wa=[0]*(n+1)

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

ans=0
for i in range(n-k+1):
    kitai=k+wa[i+k]-wa[i]
    if kitai>ans:
        ans=kitai
ans/=2
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#x,y = map(lambda x: int(x), input().split())
#list = list(map(lambda x: int(x), input().split()))


n,k = map(lambda x: int(x), input().split())
p_lst = list(map(lambda x: int(x), input().split()))


def cum_sum(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append(list[i])
        else:
            result.append(result[i-1] + list[i])
    return result


def cum_sum_exp(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append((list[i]+1)/2)
        else:
            result.append(result[i-1] + (list[i]+1)/2)
    return result



cum_sum_main = cum_sum_exp(p_lst)


cmp = cum_sum_main[k-1]


for i in range(k-1,n):
    if i == k-1:
        cmp = cum_sum_main[i]
    else:
        tmp = cum_sum_main[i] - cum_sum_main[i-k]

        if cmp < tmp:
            cmp = tmp



print(cmp)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

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

Submission status: Accepted

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

    ev = [(num + 1) / 2 for num in p]

    cumsum = []
    c = 0
    for num in ev:
        c += num
        cumsum.append(c)
    cumsum.append(0)  # let cumsum[-1] be 0
    
    ans = 0
    for i in range(n):
        if i + k - 1 > n - 1:
            break
        nominee = cumsum[i+k-1] - cumsum[i-1]
        if nominee > ans:
            ans = nominee

    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC154D 累積和
from itertools import accumulate
N, K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x:(x+1)/2, p))
P = list(accumulate([0]+p))
ans = 0
for i in range(N-K+1):
    if P[i+K]-P[i]>= ans:
        ans = P[i+K]-P[i]
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]+1)/2.
ans = S
for i in range(N-K):
    S += (P[i+K]-P[i])/2.
    ans = S if S > ans else ans 

print(ans)