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 = [int(i) for i in input().split(' ')]
input_list = [int(i) for i in input().split(' ')]
 
maximum = sum(input_list[:k])
s = sum(input_list[:k])
for i in range(1, n-k+1):
  s = s - input_list[i-1] + input_list[i+k-1]
  maximum = max(maximum, s)

print( (maximum + k) / 2 )

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(K):
    sum += A[i]
li.append(sum)
for i in range(N - K):
    sum -= A[i]
    sum += A[i+K]
    li.append(sum)


print(max(li))

Submission status: Accepted

Solution code:
import numpy as	np
N,K=map(int,input().replace('\n','').split())
P=list(map(int,input().replace('\n','').split()))

s=np.sum(P[0:K])
m=s
for i in range(1,N-K+1):
  s=s-P[i-1]+P[i+K-1]
  if s>=m:
    m=s
	
print((m+K)/2)

Submission status: Accepted

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

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


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


ex_list = []
for i in range(N):
    ex_list += [expected_value(P[i])]

sum_list = []
for i in range(N+1-K):
    if i == 0:
        sum_list += [sum(ex_list[i:i+K])]
    if i >= 1:
        sum_list += [sum_list[i-1] + ex_list[i+K-1] - ex_list[i-1]]

print(max(sum_list))

Submission status: Accepted

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

MX = 0
ttl = 0

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

mm = ttl

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

print((ttl+K)/2)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
List = list(map(int, input().split()))
score = []
score1 = []

def cal_score(num):
    return 1 + 0.5 * (num - 1)

score.append(cal_score(List[0]))

for i in range(1, n):
    score.append(score[i - 1] + cal_score(List[i]))
    
score1.append(score[k - 1])
m = 0
for i in range(k, n):
    score1.append(score[i] - score[m])
    m += 1

#print(score)    
#print(score1)
print(max(score1))

Submission status: Accepted

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

ans=max(pA)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))


sum1=sum(a1[:q1[1]])
sumsum=sum1
for i in range(q1[0]-q1[1]):
    sum1=sum1+a1[i+q1[1]]-a1[i]
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)

Submission status: Accepted

Solution code:
from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())
    p_list = [(p+1)/2 for p in list(map(int,input().split()))]

    # Sを計算
    S = [0]
    for p in p_list:
        S.append(S[-1] + p)
        # print(S)

    # i:i+kを計算

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = tmp = sum(L[:K])

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

print(ans)

Submission status: Accepted

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

number = sum(p[0:y])
bigNumber = number

for i in range(x-y):

    number = number - p[i] + p[i+y]

    if number > bigNumber:
        bigNumber = number

print((bigNumber + y) / 2)

Submission status: Accepted

Solution code:
n,k=(int(x) for x in input().split())
lst=[int(x) for x in input().split()]
sum_lst=[sum(lst[0:k])]
for i in range(n-k):
  next_element=sum_lst[-1]-lst[i]+lst[i+k]
  sum_lst.append(next_element)
print((max(sum_lst)+k)/2.0)

Submission status: Accepted

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

    number = sum(p[0:y])
    bigNumber = number

    for i in range(x-y):

        number = number - p[i] + p[i+y]

        if number > bigNumber:
            bigNumber = number

    print((bigNumber + y) / 2)

main()

Submission status: Accepted

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

li_kitai = list()
d_kitai_memo = dict()
for l in li_p:
    if l not in d_kitai_memo:
        val = sum(range(1, l + 1)) / l
        d_kitai_memo[l] = val
        li_kitai.append(val)
    else:
        li_kitai.append(d_kitai_memo[l])

answer = 0
memo = 0
for idx, v in enumerate(li_kitai[:len(li_kitai) - k + 1]):
    if idx == 0:
        memo = sum(li_kitai[idx:idx + k])
    else:
        memo = memo - li_kitai[idx - 1] + li_kitai[idx + (k - 1)]
    answer = max(answer, memo)

print(answer)

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int, input().split())
p = [(int(i)+1)/2 for i in input().split()]
s = [0]*N
s[0] = p[0]
if N==K:
    print(sum(p))
else:
    for i in range(N-1):
        s[i+1] = s[i]+p[i+1]
    ans=max(s[i+K]-s[i] for i in range(N-K))
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np

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

ans_temp = 0
ans_list = []
S = [0]
for i in range(n):
    S.append(S[i]+p[i])
# print(p)
# print(S)
# for i in range(n-k+1):
#     ans_list.append(sum(p[i:i+k]))
t_len = len(S)
ans1 = 0
for i in range(t_len - k):
    if ans1 < S[i+k]-S[i]:
        ans1 = S[i+k]-S[i]
print(ans1)
# ans = 0
# for i in range(k):
#     ans += (ans_list[i]*(ans_list[i]+1)/2)/ans_list[i]
#     # print((ans_list[i]*(ans_list[i]+1)/2))
# print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().strip().split())
arr = [int(i) for i in input().strip().split()]
maxi = s = (sum(arr[0:k]) + k) / 2
for i in range(1, n - k + 1):
  s += (arr[i + k - 1] - arr[i - 1]) / 2
  if s > maxi: maxi = s
print(maxi)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    p = [((int(i)+1) * int(i) / 2)/int(i) for i in input().split()]
    result = sum(p[:K])
    prev = result
    for i in range(0, N-K):
        prev = prev - p[i] + p[i+K]
        result = max(result, prev)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    N,K = map(int,input().split())
    a = list(map(int,input().split()))
    cum = [0]
    for num in a:
        cum.append(cum[-1]+num)
    M = 0
    for i in range(N-K+1):
        M = max(M,cum[i+K]-cum[i])
    
    print((M+K)/2)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

# 累積和
def cumsum(a):
    r = [0]
    for v in a:
        r.append(r[-1] + v)
    return r

cs = cumsum(p)

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

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
 
dice = list(map(int, input().split()))
 
a = sum(dice[0: k])
b = sum(dice[0: k])
 
res = 0
ll = 0
s = 0

for i in range(k, len(dice)):
    a += dice[i]
    a -= dice[i - k]
    if a > b:
        b = a
 
res = (b + k) /2.0
 
print(res)

Submission status: Accepted

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


if n==k:
    print(sum(p))
else:
    sump = [0]*n
    sump[0]=p[0]
    for i in range(n-1):
        sump[i+1] = sump[i]+p[i+1]
    ans=max(sump[i+k]-sump[i] for i in range(n-k))
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
p_sum = [0]
max = 0

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

for i in range(K,N+1):
    sum = p_sum[i] - p_sum[i-K]
    if(max < sum):
        max = sum
# for i in range(N-K+1):
#     tmp = p[i]
#     # print("i:" + str(i))
#     for j in range(i+1,i+K):
#         tmp += p[j]

#     # print(tmp)
#     if(max < tmp):
#         max = tmp 
#         maxStartIndex = i
# ans = 0
# for i in range(maxStartIndex, maxStartIndex+K):
#     sum = p[i] * (p[i]+1) / 2
#     ans += sum/p[i]
print('{:.12f}'.format(max))
# 1 2 3 
# 3 2 1


# n, n-1, n-2
# n(n + 1)/2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []
y = 0
for x in range(1, 1001):
    y += x
    l.append(y/x)
m = []
for i in p:
    m.append(l[i-1])
s = [0]
z = 0
for i in m:
    z += i
    s.append(z)
ans = []
for i in range(n-k+1):
    ans.append(s[i+k] - s[i])
print(max(ans))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []
y = 0
for x in range(1, 1001):
    y += x
    l.append(y/x)
m = []
for i in p:
    m.append(l[i-1])
s = [0]
z = 0
for i in m:
    z += i
    s.append(z)
ans = 0
for i in range(n-k+1):
    ans = max(ans, s[i+k] - s[i])
print(ans)

Submission status: Accepted

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

expectations = [(((1 + i) * i) / 2) / i for i in p] # O(n)
i = 0
MAX = e = sum(expectations[i:i + k])
while i + k < n: # O(n)
    i += 1
    t = e - expectations[i - 1] + expectations[i + k - 1]
    MAX = max(MAX, t)
    e = t

print(MAX)

Submission status: Accepted

Solution code:
import collections

def get_input_line():
    return list(map(int, input().split()))
n, k = get_input_line()
p_list = get_input_line()

def calc_dice_score(p):
    return 0.5*(p+1)

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0] * n

max_score = 0
tmp_score = 0

for i in range(k):
    dice_scores[i] = 0.5*(p_list[i]+1)
    tmp_score += dice_scores[i]

max_score = tmp_score
for i in range(1, n- k + 1):
    dice_scores[i+k-1] = 0.5*(p_list[i+k-1]+1)
    tmp_score -= dice_scores[i-1]
    tmp_score += dice_scores[i+k-1]
    max_score = max(max_score, tmp_score)
print(max_score)

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
tmp=0
for i in range(k):
  tmp+=p[i]
t=[tmp]
for j in range(1,n-k+1):
  tj=t[j-1]-p[j-1]+p[j+k-1]
  t.append(tj)
t.sort()
print(t[n-k])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

B = []
for j in range(N-K+1):
    B.append(S_list[j+K]-S_list[j])
ans = max(B)
print(ans)

Submission status: Accepted

Solution code:
def calc_e(num):
    return (num + 1) / 2

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

    current = (sum(dices[:k]) + k) / 2
    e_max = (sum(dices[:k]) + k) / 2
    for i in range(n-k):
        current = current + calc_e(dices[i+k]) - calc_e(dices[i])
        e_max = max(e_max, current)

    print(e_max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
L = list(map(int, input().split()))
E = [(v+1)/2 for v in L]
tmp = sum(E[:K])
ans = tmp
for l, p in zip(E[K:], E):
    tmp = tmp+l-p
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
P = [0]*N
E = [0]*N
ev = [0]*(N+1)
EV = [0]*(N-K+1)

for i in range(N):
    P[i] = (p[i]+1)*p[i]/2
    E[i] = P[i]/p[i]
if N==K:
    print(sum(E))
elif K==1:
    print(max(E))
else:
    for i in range(N):
        ev[i+1] = ev[i]+E[i]
    for i in range(N-K+1):
        EV[i]=ev[i+K]-ev[i]
    print(max(EV))

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    P=LI()
    Q=[(1+p)*p/2/p for p in P]
    now = sum(Q[:K])
    ans = now
    for i in range(N-K):
        now -= Q[i]
        now += Q[i+K]
        ans = max(ans, now)
    print(ans)
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()))
P = [0]+[(p+1)/2 for p in P]
S = list(accumulate(P))
B = []
for j in range(N-K+1):
    B.append(S[j+K]-S[j])
ans = max(B)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split(" "))
dices_e = [float((e+1)/2) for e in list(map(int, input().split(" ")))]
e = max_e = sum(dices_e[:k])
for i in range(1, n-k+1):
  e = e - dices_e[i-1] + dices_e[i+k-1]
  if e>max_e:
    max_e = e

print(max_e)

Submission status: Accepted

Solution code:
import itertools

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

pa = list(itertools.accumulate([0] + p))

m = 0
for i in range(n-k+1):
  s = pa[i+k] - pa[i]
  if s > m:
    m = s
print((m+k)/2)

Submission status: Accepted

Solution code:
def expectation(li):
  total = 0
  for i in li:
    total += (i+1)/2
  return total

n,k = map(int,input().split())
p = list(map(int,input().split()))
ex = expectation(p[0:k])
li = [ex]
for i in range(1,n-k+1):
  ex = ex - (p[i-1]+1)/2 + (p[i+k-1]+1)/2
  li.append(ex)
print(max(li))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
list_pn=list(map(int,input().split()))
# Pnの期待値を計算
pn_ave=[]
for i in range(N):
    pn_ave.append((list_pn[i]+1)/2)
# Sj+k-Sjの累積和を用いて考える
Sj = []
Sj.append(0)
S=0
for i in range(N):
    S += pn_ave[i]
    Sj.append(S)
# print(Sj)
Sk = []
for i in range(N-K+1):
    Sk.append(Sj[i+K]-Sj[i])
# print(Sk)
Sk.sort()
print(Sk[-1])

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split()]
p = [1/2 + int(x)/2 for x in input().split()]
sum_p =[]
buf = 0
for i in p:
    buf += i
    sum_p.append(buf)
max_t = 0
for i in range(n - k + 1):
    buf = sum_p[i+k-1]
    if i > 0:
        buf -= sum_p[i-1]
    if max_t < buf:
        max_t = buf
print(max_t)

Submission status: Accepted

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

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

ans = tmp
for i in range(1, n-k+1):
    tmp -= 0.5 * p[i-1] + 0.5
    tmp += 0.5 * p[i+k-1] + 0.5
    if ans < tmp:
        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(n):
    s=P[i]+S[i]
    S.append(s)
a=0
for i in range(k,n+1):
    a=max(a,S[i]-S[i-k])
print((a+k)/2)

Submission status: Accepted

Solution code:
dp = [0]*1001
dp[1] = 1
for i in range(2,1001):
    dp[i]=dp[i-1]+0.5

n,k = map(int,input().split())
p = list(map(int,input().split()))
s = 0
for i in range(k):
    s += p[i]
ans = 0
for i in range(n):
    if i>k-1:
        tmp = tmp + dp[p[i]] - dp[p[i-k]]
        if tmp>ans:
            ans = tmp
    else:
        ans+=dp[p[i]]
        tmp = ans
print(ans)

Submission status: Accepted

Solution code:
def main():    
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    s = sum(p[:k])
    maxs = s
    for i in range(n-k):
        s = s - p[i] + p[i+k]
        if s > maxs:
            maxs = s
    ans = (maxs+k)/2
    print(ans)
main()

Submission status: Accepted

Solution code:
N,K = map( int, input().split() )
p = list( map( int, input().split() ) )
q = [0]
total = 0
for i in range(N):
    total += p[i]
    q.append(total)

t = 0
for i in range(N-K+1):
    t = max( q[i+K] - q[i],t )

print( (K+t)/2 )

Submission status: Accepted

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

Submission status: Accepted

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

x = 0.0
SUM = [0.0]
for e in E:
    x += e
    SUM += [x]

MAX = 0
for i in range(N-K+1):
    a = SUM[i+K] - SUM[i]
    if a > MAX:
        MAX = a

print(MAX)

Submission status: Accepted

Solution code:
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('d3.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def gen():
  N = 200000
  K = 4000
  p = [6] * N
  print(N, K)
  print(*p)


def main():
    N, K = read_int_list()
    p = read_int_list()
    cp = [0] * (N+1)
    for i in range(N):
      cp[i+1] = cp[i] + (p[i]+1)/2
    # print(p)
    # print(cp)
    # print()
    res = 0    
    for i in range(N-K+1):
      # print(cp[i], cp[i+K], cp[i+K]-cp[i])
      if cp[i+K]-cp[i] > res:
        res = cp[i+K]-cp[i]
    
    print(res)


# gen()
main()

Submission status: Accepted

Solution code:
import numpy as np

N, M = list(map(int, input().split()))
num_array = np.cumsum(list(map(lambda x: (x+1)/2, list(map(int, input().split())))))

max_exp = num_array[M-1]
for i in range(len(num_array)-M):
    tmp = num_array[i+M] - num_array[i]
    if max_exp < tmp:
        max_exp = tmp

print(max_exp)

Submission status: Accepted

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

values = [(p+1)/2 for p in ps]

ans  = sum(values[:K])
# print(values)
tmp = ans
for i in range(K,N):
    # print(i,tmp)
    tmp = tmp - values[i-K] + values[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=sum(p[0:K])
d=0
e=0
for i in range(N-K):
  d+=p[i+K]-p[i]
  if d>e:
    e=d
s+=e
print((s+1*K)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    pp=list(map(int,input().split()))
    m=s=sum(pp[i] for i in range(k))
    for i in range(k,n):
        s=s-pp[i-k]+pp[i]
        if s>m:
            m=s
    print(0.5*k+0.5*m)

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

P = [0 for n in range(N - K + 1)]

P[0] = sum([p[i] for i in range(K)])

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# print(N,K)
p = list(map(int, input().split()))
# print(p)
# 1 から P までの P 種類の目が等確率で出るサイコロの出目の期待値は (1 + P)/2 です。
p_exp = [(1+i)/2 for i in p]
# print('期待値が入ったリストp')
# print('p='+ str(p_exp))
# 期待値が入ったリストpができた
# 新たに累積和リストSを作成する
S =[0] * N
S[0] = p_exp[0]
for i in range(len(p_exp) - 1):
    S[i + 1] = S[i] + p_exp[i + 1]
# print('累積和が入ったリスト')
# print('S=' + str(S))
S.insert(0, 0)
# print('累積和が入ったリストに先頭0挿入したリスト')
# print('S=' + str(S))
max =0
exp_sum = 0
for j in range(N - K + 1):
    exp_sum = S[j + K] - S[j]
    if max < exp_sum:
        max = exp_sum
# print('求める最大値maxは')
# print('max=' + str(max))
print(max)

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
for i in range(N):
    p[i] = (1+p[i])/2
s = sum(p[:K])
max_s = s
for i in range(N-K):
    max_s+=p[K+i]
    max_s-=p[i]
    if max_s>s:
        s = max_s
print(s)

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
p =[]
for i in b:
    p.append((i+1)/2)
s = sum(p[:K])
max_s = s
for i in range(N-K):
    max_s+=p[K+i]
    max_s-=p[i]
    if max_s>s:
        s = max_s
print(s)

Submission status: Accepted

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

ans = sum(p[:k])

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

anss = [0] * n
for i in range(n-k):
  anss[i] = psum[i+k] - psum[i]

print((max(ans, max(anss))+k)/2)

Submission status: Accepted

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

p = list(map(lambda x: (sum(list(range(x + 1)))) / x, p))
tmp = sum(p[:k])
ans = tmp
for i in range(1, (n - k + 1)):
    tmp = tmp + p[i + k - 1] - p[i - 1]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n,k = (int(x) for x in input().split())
ln = list(map(float, input().split()))
ln_mean=[1+0.5*(x-1) for x in ln]
#print(ln_mean)

if n == k:
  print(sum(ln_mean))
else:
  lnk = [0]*(n-k+1)
  m_in = 0
  for i in range(k):
    m_in += ln_mean[i]
  m_max = m_in
  tmp_max = m_in
  for i in range(n-k):
    tmp_max = tmp_max - ln_mean[i] + ln_mean[i+k]
    if m_max < tmp_max:
      m_max = tmp_max
  print(m_max)

Submission status: Accepted

Solution code:
from itertools import accumulate


def solve(string):
    n, k, *p = map(int, string.split())
    *p, = accumulate((1 + _p) / 2 for _p in p)
    return str(max(p2 - p1 for p1, p2 in zip(p, p[k:]))) if k < n else str(p[-1])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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


def modify(x):
    return int(x) + 1


l = list(map(modify, input().split()))

s = sum(l[:k])
m = s
for i in range(k, n):
    s += l[i]
    s -= l[i-k]
    m = max(s, m)

print(m/2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, k = LI()
    p = LI()
    dp = [0] * n
    bf = list(itertools.accumulate([i for i in range(1001)]))
    for i in range(n):
        dp[i] = bf[p[i]] / p[i]
    ans = 0
    bf = 0
    for i in range(k):
        ans += dp[i]
    bf = ans
    for i in range(k, n):
        bf -= dp[i - k]
        bf += dp[i]
        ans = max(ans, bf)
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

exp = [] #期待値のリスト
exp.append(0) #０の期待値
count = 1
max = 0
tmp = 0

for i in range(1,1001):
    exp.append(count/i)
    count = count + (i+1)

#まず最初のK個の期待値を求める
for i in range(n[1]):
    tmp = tmp + exp[p[i]]
if(tmp >= max):
    max = tmp

#尺取り法でK+1個目の期待値を足して、j(0から増えていく＝先頭の期待値)を引いていく
for j in range(n[0]-n[1]):
    #print(j,tmp)
    tmp = tmp + exp[p[j+n[1]]] - exp[p[j]]
    if(tmp >= max):
        max = tmp

print(max)

Submission status: Accepted

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

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

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
# 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)])
 
def main():
    n,k = inpm()
    p = inpl()
    for i in range(n):
        p[i] = (1+p[i])/2
    cnt = 0
    for i in range(k):
        cnt += p[i]
    ans = cnt
    for i in range(n-k):
        cnt -= p[i]
        cnt += p[i+k]
        ans = max(ans,cnt)
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

for i in range(n-k):
  a = a - p[i] + p[i+k]
  if s < a:
    s = a
  
print(s)

Submission status: Accepted

Solution code:
N,T = input().split(' ')
ps = input().split(' ')
N=(int)(N)
T=(int)(T)

def E_cal(i):
    return (i+1)/2

Es=[]

ruiseki_sum=[0]

for i,p in enumerate(ps):
    Es.append(E_cal((int)(p)))
    ruiseki_sum.append(Es[i]+ruiseki_sum[i])

#print(Es)
#print(ruiseki_sum)
TEs_max = 0

for j in range(N-T+1):
    now = ruiseki_sum[j+T]-ruiseki_sum[j]
    if now>TEs_max:
        TEs_max=now
    #print(now)
print(TEs_max)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 12 16:38:08 2020

@author: matsui
"""

N,K=map(int,input().split())
p=[int(num) for num in input().split()]

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

M=0
for i in range(N-K+1):
    #print(i+K,i)
    if dp[i+K]-dp[i] > M: M=dp[i+K]-dp[i]
    
print(M)

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(a[0]):
  b[i]=(b[i]+1)/2
c=0
for i in range(a[1]):
  c+=b[i]
c=[c]
for i in range(1,a[0]-a[1]+1):
  d=c[i-1]
  d+=b[i+a[1]-1]-b[i-1]
  c.append(d)
print(max(c))

Submission status: Accepted

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

max=0
tmp=0
for x in range(0,K):
    max+=p[x]
    tmp+=p[x]
for i in range(K,N):
    tmp=tmp+p[i]-p[i-K]
    if tmp>max:
        max=tmp
print((max+K)*0.5)