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:
def examA():
    def calc_L(x1,y1,x2,y2):
        return ((x2-x1)**2 + (y2-y1)**2)**0.5
    N = I()
    X = [LI()for _ in range(N)]
    ans = 0
    for x in itertools.permutations(X):
        cur = 0
        for i in range(1,N):
            cur += calc_L(x[i-1][0],x[i-1][1],x[i][0],x[i][1])
        #print(x,cur)
        ans += cur
    for i in range(1,N+1):
        ans /= i
    print(ans)
    return

def examB():
    def judge(n):
        sn = 0
        for i in n:
            sn += int(i)
        if int(n)%sn==0:
            return "Yes"
        return "No"
    N = SI()
    ans = judge(N)
    print(ans)
    return

def examC():
    N, K = LI()
    P = LI()
    ans = 0
    S = [0]*(N+1)
    for i in range(N):
        S[i+1] = S[i]+(P[i]+1)/2
    for i in range(N-K+1):
        cur = S[i+K] - S[i]
        if cur>ans:
            ans = cur
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 154
# D - Dice in Line
# https://atcoder.jp/contests/abc154/tasks/abc154_d
N, K = map(int, input().split())
*A, = map(int, input().split())

E = [0]*N

for i, a in enumerate(A):
    E[i] = (a+1)/2

L = [0]*N

L[0] = E[0]
for i in range(1, N):
    L[i] = L[i-1]+E[i]


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

Submission status: Accepted

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

s = sum((pi+1)/2 for pi in p[:K])
m = s
for i, pi in enumerate(p):
    if i < K:
        continue
    s -= (p[i-K]+1)/2
    s += (p[i]+1)/2
    if s > m:
        m = s

print(m)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = [0]+list(map(int,input().split()))
kit = [0]*(max(p)+1)
for i in range(1,max(p)+1):
    kit[i] = (i*(i+1)//2)/i
for i in range(n):
    p[i+1] = kit[p[i+1]]
    p[i+1] +=p[i]
ans = 0
for i in range(n):
    l = i
    r = i+k
    if r >n:break
    s = p[r] - p[l]
    ans = max(ans,s)
print(ans)

Submission status: Accepted

Solution code:
# Problem D - Dice in Line

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

# initialization
kitai_list = [0]*N
for i in range(N):
    p = p_list[i]
    p_sum = (1 + p)*p / 2
    p_ave = p_sum / p
    kitai_list[i] = p_ave
max_score = -1

# count
tmp = 0
for i in range(N):
    if i-K<0:
        tmp += kitai_list[i]
        max_score = max(max_score, tmp)
    else:
        tmp -= kitai_list[i-K]
        tmp += kitai_list[i]
        max_score = max(max_score, tmp)

# output
print(max_score)

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
p = list(map(int,input().split()))
cs = []
for x in p:
    cs.append(((x+1)*x//2)/x)
cs = [0]+np.cumsum(cs).tolist()
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())
p=list(map(int,input().split()))
e=[]
for pp in p:
    e.append((pp+1)/2)
ans=0
t=0
for i in range(n-k+1):
    if i==0:
        t=sum(e[:k])
        ans=t
        continue
    t-=e[i-1]
    t+=e[i+k-1]
    ans=max(ans,t)
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
# p[i]での出目の期待値
P = [(int(i) + 1) / 2 for i in input().split()]

from itertools import accumulate

P = [0] + list(accumulate(P))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
for i in range(n):
    a[i] = (a[i]+1)/2
cnt = sum(a[:k])
res = cnt
for i in range(n-k):
    cnt -= a[i]
    cnt += a[k+i]
    res = max(res,cnt)
print(res)

Submission status: Accepted

Solution code:
from itertools import accumulate



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


def main():
    n, k = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    n += 1
    for i in range(1, n):
        p[i] = expectation(p[i])
    p = list(accumulate(p))
    answer = 0
    for i in range(n - k + 1):
        answer = max(answer, p[i + k - 1] - p[i - 1])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

pl = [(p+1) / 2 for p in pl]
import itertools

pl_ac = [0] + list(itertools.accumulate(pl))

ans = 0
for i in range(len(pl_ac) - k):
    ans = max(ans, pl_ac[i + k] - pl_ac[i])

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
ruiseki = [0]*(N+1)
now = 0
maximum = -999999999
ans = 0
p = list(map(int,input().split()))
for i in range(N):
    now += p[i]
    ruiseki[i+1] = now
for i in range(0,N-K+1):
    P = ruiseki[i+K]-ruiseki[i]
    if P > maximum:
        maximum = P
        Q = p[i:i+K]
for i in range(len(Q)):
    ans += (0.5*Q[i]*(Q[i]+1))/Q[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sm = sum(ds[:K])
out = sm
for i in range(N-K):
    sm = sm-ds[i]+ds[i+K]
    out = max(out,sm)

print((out+K)/2)

Submission status: Accepted

Solution code:
#D
#モジュール
import numpy as np

#入力
N,K=map(int,input().split())
P=np.array(list(map(int,input().split())))

#諸関数
def pront(X):
    #デバッグ用プリント
    #環境変数としてdebugを確保して、それが1なら内容を出力
    if debug==0:
        print(X)

#デバッグ用
debug=1#0:本番,1:デバッグ中



#処理
pront(P)
#関数
def d_1(p):
    #1~pまででるサイコロの期待値を返す
    return((p+1)/2)
#ここまで

P=list(d_1(P))

pront(P)

X=[0]
for i in range(N):
    if i==0:
        X.append(P[i])
    else:
        X.append(P[i]+X[-1])
result=-1
pront(X)
for i in range(N-K+1):
    cal=X[i+K]-X[i]
    if result<cal:
        result=cal
print(result)

Submission status: Accepted

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

maxsum = -1
cul = sum(pe[0:k])
maxsum = cul
for i in range(1,n-k+1):
    cul = cul - pe[i-1] + pe[i+k-1]
    if cul > maxsum:
        maxsum = cul
print(maxsum)

Submission status: Accepted

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

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

tmp = sum(P[0:K])
result = tmp

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

print((result+K)/2)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

cumsum = [0] + list(accumulate(P))
# print(cumsum)

res = []
for i in range(N-K+1):
    res.append(cumsum[i+K] - cumsum[i])

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

Submission status: Accepted

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

excepted = [(v*(v+1) / 2) / v for v in p]

left = 0
right = 0

ans = 0
tmp = 0

while True:
    ans = max(tmp,ans)
    if left == n : break
    if right - left < k and right != n:
        tmp += excepted[right]
        right += 1
    else:
        tmp -= excepted[left]
        left += 1

print(ans)

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]

cumsum = [0]*(N+1)
for i in range(1, N+1):
    cumsum[i] = cumsum[i-1] + P[i-1]
ans = 0
for i in range(N-K+1):
    if ans < cumsum[i+K]-cumsum[i]:
        ans = cumsum[i+K]-cumsum[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
i = k
total = maximum = sum(p[0:k])
i = k
while i < n:
    total = total-p[i-k]+p[i]
    maximum = max(maximum, total)
    i += 1
print((maximum+k)/2)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
pn = list(map(int,input().split()))
num = [0]*(N-K+1)
num[0] = sum(pn[0:K])
for n in range(1,N-K+1):
  num[n] = num[n-1] - pn[n-1] + pn[n+K-1]
print(0.5*(K + max(num)))

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
Ps = np.array(input().split(), dtype=int)

cumsum = Ps.cumsum()
cumsum = np.concatenate([[0], cumsum])
moving_cumsum = cumsum[K:] - cumsum[:-K]

res = (moving_cumsum.max() + K) / 2
print(res)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(lambda pi: (int(pi) + 1) / 2, input().split()))
ex = sum(p[:k])
mx = ex
for i in range(n - k):
    ex += p[i + k] - p[i]
    if mx < ex:
        mx = ex
print(mx)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
p = list(map(int, input().split()))
p = [(1+i)/2 for i in p]
# 累積和の配列sを作成する
s = [0] * (n+1)
for i in range(1,n+1):
    s[i] = s[i-1] + p[i-1]
max = -1 * float("inf")
for i in range(n-k+1):
    sum = s[k+i] - s[i]
    if max <= sum:
        max = sum
print(max)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
goukei = 0
max = 0
startnum = 0
for i in range(K):
    goukei += P[i]

for i in range(N-K):
    goukei = goukei - P[i] + P[i+K]
    if goukei > max:
        max = goukei
        startnum = i+1
        
answer = 0
for i in range(startnum,startnum+K):
    n = P[i]
    answer += n*(n+1)/2/n
print(answer)

Submission status: Accepted

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

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

temp = sum(e_list[:k])
ans = temp

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

print(ans)

Submission status: Accepted

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

    P = [(1+p)/2 for p in P]
    p_sum = [sum(P[:K])]
    for i in range(K, N):
        p_sum.append(p_sum[-1] - P[i-K] + P[i])
    print(max(p_sum))

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()))
kt = []
for i in range(n):
    kt.append((p[i]*(p[i]+1)/2/p[i]))
skt = sum(kt)

ac = [0] + list(accumulate(kt))
ans = -float('inf')
for i in range(n-k+1):
    ans = max(ans, ac[i+k] - ac[i])
print(ans)

Submission status: Accepted

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

sum_p = 0
sum_list = []
sum_list.append(sum_p)
for p_element in p:
    sum_p += p_element 
    sum_list.append(sum_p)

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

answer = 0
for i in range(K):
    answer += (1+p[start+i])/2
print(answer)

Submission status: Accepted

Solution code:
import queue
q = queue.Queue()
N,K = map(int,input().split())
ds = list(map(int,input().split()))

sm = sum(ds[:K])
out = sm
for i in range(N-K):
    sm = sm-ds[i]+ds[i+K]
    out = max(out,sm)

print((out+K)/2)

Submission status: Accepted

Solution code:
N,K=input().split()
n,k=int(N),int(K)
p=list(input().split())
ans = 0

for i in range (len(p)):
    p[i]=int(p[i])

pre=[0 for i in range (n+1)]
q=[0 for i in range (n-k+100)]


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

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

print ((ans + k) / 2)

Submission status: Accepted

Solution code:
N,K=input().split()
n,k=int(N),int(K)
p=list(input().split())
ans = 0

for i in range (len(p)):
    p[i]=int(p[i])

pre=[0 for i in range (n+1)]
q=[0 for i in range (n-k+100)]


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

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

print ((ans + k) / 2)

Submission status: Accepted

Solution code:

n,k = map(int, input().split())
p = [ int(x) for x in input().split()]

sm = sum(p[:k])
adj_sum = [sm]
for i in range(k,n):
  sm -= p[i-k]
  sm += p[i]
  adj_sum.append(sm)
  
mx = max(adj_sum)
print((mx+k)/2)

Submission status: Accepted

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

e = [(i+1)/2 for i in p]
e = np.cumsum(e)
e = np.append(0,e)
ans = 0
for i in range(n-k+1):
    ans = max(e[i+k]-e[i],ans)
print(ans)

Submission status: Accepted

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


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

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
plist = [((num*(num+1))//2)/num for num in list(map(int, input().split()))]
# print(plist)
ans = 0
for i in range(K):
    ans += plist[i]
_ = ans
for i in range(N-K):
    temp = _
    temp -= plist[i]
    temp += plist[i+K]
    # print(i, i+K, ans, temp)
    ans = max(ans, temp)
    _ = temp
print(ans)

Submission status: Accepted

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

E = [(x*(x+1))/2/x for x in range(1, 1001)]
E = [0.0] + E

P = [E[int(p)] for p in input().split()]

ans = sum_ = sum(P[:K])

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

print(ans)

Submission status: Accepted

Solution code:
def main():  
  import sys
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  import numpy as np #pypy不可
  n,k = map(int,readline().split())
  p =  np.array(read().split(),np.int32)
  np.cumsum(p,out=p)
  chk = p[k-1]
  for i in range(n-k):
    c = p[i+k]-p[i]
    chk = max(c,chk)
  print((chk+k)/2)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(K):
    ans += p[i]
    tt = ans
for i in range(K,N):
    tt = tt+p[i]-p[i-K]
    ans = max(ans, tt)
print((ans + K)/2)

Submission status: Accepted

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
p=n1()

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

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

Submission status: Accepted

Solution code:
import sys
n, k = map(int, input().split())
p = list(map(int, input().split()))
# 下の同値の場合を除外しないとrange(k,k)=[]となりfor文が回らない
if n == k:
    print((sum(p) + k) / 2)
    sys.exit(0)
saveSum = sum(p[0:k])
M = 0
for i in range(k, len(p)):
    saveSum = saveSum + p[i] - p[i - k]
    if saveSum > M:
        M = saveSum
print((k+M)/2)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
max_total = 0
res = 0
p = list(map(int,input().split()))
for _ in range(len(p)):
  p[_] = (p[_]+1)/2
  
total = sum(p[0:K])
max_total = total
for i in range(K,N):
  if p[i] > p[i-K]:
    total = total + p[i] - p[i-K]
    max_total = max(max_total,total)
  else:
    total = total + p[i] - p[i-K]

print(max_total)

Submission status: Accepted

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

from collections import deque

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = 0
mx = 0

q = deque()

for a in range(N):
    sm += exv[a]
    q.appendleft(exv[a])
    if len(q) > K:
        sm -= q.pop()
    if len(q) == K:
        mx = max(mx,sm)

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

Submission status: Accepted

Solution code:
from collections import deque
import copy
N,K = map(int, input().split())
p = list([(i+1)* i/2/i for i in map(int, input().split())])
que = deque([0]* K)
sumM = 0
sumq = 0
E = 0.0

for i in range(N):
    sumq -= que.popleft()
    sumq += p[i]
    que.append(p[i])
    if E < sumq:
        E = sumq
print(E)

Submission status: Accepted

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

Submission status: Accepted

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

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=s.split()
s=input()
p=s.split()
a=[]
a.append(int(p[0]))
now=a[0]
for i in range(1,int(n[0])):
	now+=int(p[i])
	a.append(now)
k=int(n[1])
m=a[k-1]
for i in range(k,int(n[0])):
	if m<a[i]-a[i-k] :
		m=a[i]-a[i-k]
print('{:.8f}'.format(m/2+k/2))

Submission status: Accepted

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

s = sum(p[:k])
m = s

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

print((m + k) / 2)

Submission status: Accepted

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

exp_value = (sum(dices[:k]) + k) / 2
max_exp_value = exp_value

for i in range(n - k):
  exp_value += (dices[i + k] - dices[i]) / 2
  if exp_value > max_exp_value:
    max_exp_value = exp_value

print(max_exp_value)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def calc_kitaiti(n):
    sum_n = 0
    if n % 2 == 0:
        temp = n / 2
        sum_n = (temp * n) + temp
    else:
        temp = (n - 1) / 2
        sum_n = (n * (temp + 1))

    return sum_n / n


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

    kitaitis = [0]
    pre = 0
    for _a in a:
        pre += calc_kitaiti(_a)
        kitaitis.append(pre)

    result = 0
    for i in range(k, n + 1):
        start = i - k
        result = max(result, kitaitis[i] - kitaitis[start])

    return result


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import queue
N,K=map(int,input().split())
P=list(map(int,input().split()))
que=queue.Queue()
que_tmp=queue.Queue()
ans=0
tmp=0
cnt=0
for p in P:
    if cnt<K:
        que_tmp.put(1+p)
        tmp+=1+p
        cnt+=1
    else:
        que.put(1+p)

while not que.empty():
    dis=que_tmp.get()
    plus=que.get()
    que_tmp.put(plus)
    tmp+=plus-dis
    ans=max(ans,tmp)
print(max(ans,tmp)/2)

Submission status: Accepted

Solution code:
from collections import defaultdict


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

kitai = []
for i in p:
    if not pd[i]:
        ex = (1 + i) / 2
        kitai.append(ex)
    else:
        kitai.append(pd[i])

# 累積和
rui = []
for i, j in enumerate(kitai):
    if i == 0:
        rui.append(j)
    else:
        rui.append(rui[i-1] + j)

ans = 0
for i, j in enumerate(rui):
    if i + (K-1) >= N:
        continue
    else:
        if i == 0:
            ans = rui[i+K-1]
        else:
            ans = max(ans, rui[i+K-1] - rui[i-1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
def expect(i):
    return (i+1) / 2


S=[0]

for i, x in enumerate(p, start=1):
    S.append(S[i-1] + expect(x))
    
ans = 0    

for i in range(N - K + 1):
    r = S[i+K] - S[i]
    if r > ans:
        ans = r
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
    
def ev(n):
    return (n+1)/2
    
from collections import deque
    
if K == N:
    print(sum(ev(a) for a in A))
else:
    deq = deque()
    
    while len(deq) < K:
        deq.append(ev(A.pop()))
    
    total = sum(i for i in deq)
    mx = total
    
    while A:
        out = deq.popleft()
        in_ = ev(A.pop())
        deq.append(in_)
        
        total -= out
        total += in_
        mx = max(mx, total)
    
    print(mx)

Submission status: Accepted

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

    p = [(p_i+1)/2 for p_i in p]
    ans = 0
    for i in range(N-K+1):
        if i == 0:
            sum_ = sum(p[i:i+K])
        else:
            sum_ = sum_ + p[i+K-1] - p[i-1]
        ans = max(ans, sum_)

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

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

print(ans)

Submission status: Accepted

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

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

print((k + ans) / 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int,input().split())
    P = [int(i) for i in input().split()]
    value = [((i + 1)  / 2 ) for i in P]
    now = sum(value[:K])
    ans = now
    for i in range(K,N,1):
        add = (value[i] - value[i - K])
        now = now + add
        if now > ans :
            ans = now

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = input().split()

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

q = 0

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

expt = [q]

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

ans = max(expt) / 2

print (ans)

Submission status: Accepted

Solution code:
n, k = list (map (int, input ().split ()))
p = [0] + list (map (int, input ().split ()))
s = [0 for i in range (n + 1)]
mx = 0
tag = 0
f = [0.0 for i in range (n + 1)]
for i in range (1, n + 1) :
    s[i] = s[i - 1] + (p[i] + 1) * p[i] / 2 / p[i]
    if (i >= k and s[i] - s[i - k] > mx) :
        mx = s[i] - s[i - k]
print (mx)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
l = list(map(int, input().split()))
el = []
sl = [0]*(n-k+1)
for i in l:
  el.append((1+i)/2)
sl[0] = sum(el[:k])
for i in range(n-k):
  sl[i+1] = sl[i]-el[i]+el[i+k]
print("{:.20}".format(max(sl)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def q4():
    from itertools import accumulate

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

    P_kitai = [0]
    # 整数1からNまでの合計は、sum = N(N+1)/2
    # 期待値は sum / N より、(N+1)/2 で表される。
    for p in P:
        P_kitai.append((p+1)/2)
    accu = list(accumulate(P_kitai))
    #print(accu)
    max_sum = 0
    for i in range(0, N-K+2):
        max_sum = max(max_sum, accu[i+K-1] - accu[i-1])
    print(max_sum)

if __name__ == '__main__':
    q4()

Submission status: Accepted

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

cur = sum(exp[:k])
ans = cur

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

print(ans)

Submission status: Accepted

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

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

max_i=-1
max_v=0
for i in range(1,n+1-k):
  if b[i+k]-b[i]>max_v:
    max_i=i
    max_v=b[i+k]-b[i]
ans=0
for i in range(k):
  ans+=(p[max_i+i]+1)/2
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    p = list(map(int, input().split()))
    q = [0]
    for i in p:
        q.append((i*(i+1)//2)/i)
    r = list(accumulate(q))
    res = 0
    for i in range(k, n+1):
        res = max(res, r[i]-r[i-k])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
sumls=[0 for _ in range(N-K+1)]
sumls[0]=sum(ls[:K])
for i in range(N-K):
  sumls[i+1]=sumls[i]+ls[K+i]-ls[i]
x=max(sumls)
print((x+K)/2.0)

Submission status: Accepted

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

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

c=[0]*len(p) #期待値

for i in range(len(p)):
  if i>0:
    c[i]=(((p[i]+1)*p[i])/(2*p[i]))+c[i-1]
  else:
    c[i]=(((p[i]+1)*p[i])/(2*p[i]))

maxev=0

for i in range(len(p)-k+1):
  ev=0

  if i==0:
    ev=c[i+k-1]
  else:
    ev=c[i+k-1]-c[i-1]

  if maxev==0 or maxev<ev:
    maxev=ev

print(maxev)