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:
import sys

sys.setrecursionlimit(10 ** 7)

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

sk = sum(P[:K])
n = sum(P[:K])
for i in range(N):
    if i < K:
        continue

    n -= P[i - K]
    n += P[i]

    sk = max(sk, n)
    prev = n

ans = sk / 2. + K / 2.
print(ans)

Submission status: Accepted

Solution code:
n,k  = map(int,input().split())
p = list(map(int, input().split()))
current_best = 0
sum_list = [(1+p[0])/2]

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

#累積和の計算
for i in range(n-1):
  sum_list.append(sum_list[-1]+(1+p[i+1])/2)
  
if n==k:
  print(sum_list[-1])
  exit()
  
for j in range(n-k):
  expect = sum_list[j+k]-sum_list[j]
  if expect > current_best:
    current_best = expect
print(current_best)

Submission status: Accepted

Solution code:
from itertools import accumulate

N, K = map(int, input().split())
P = map(int, input().split())
acc_P = list(accumulate(P))
ans = (acc_P[K-1] + K) / 2

for i in range(N-K):
    ans = max(ans, (acc_P[i+K] - acc_P[i] + K) / 2)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nk  = list(map(int,input().split()))
p = list(map(int,input().split()))
s = [0] * (nk[0])
for j in range(nk[1]):
    s[0] += p[j]

for i in range(nk[0]-nk[1]):
    s[i+1] = s[i] - p[i] + p[i+nk[1]]

print((max(s)+nk[1])/2)

Submission status: Accepted

Solution code:



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

rui=[]
rui.append(p[0]/2+0.5)
for i in range(1,n):
    rui.append(rui[i-1]+(p[i]/2+0.5))

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

Submission status: Accepted

Solution code:
def main():
    N, K  = map(int, input().split())
    P = list(map(int, input().split()))
    best = sum(P[:K]) # sum of first K terms
    curr = best # tmp var for iteration
    for i in range(N - K):
        curr += P[i+K] - P[i] # slide window
        best = max(best, curr)
    print((best + K) / 2) # based on n(n+1)/2 == sum(range(1, n))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
p = [int(i) for i in input().split()]

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

ans = 0
tmp = 0
for i in range(k):
    tmp += kitai[i]
ans = tmp
for i in range(n - k):
    tmp = tmp - kitai[i] + kitai[i + k]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
def main():
    # 差分だけ微調整する解法
    N, K = map(int, input().split(" "))
    p = list(map(int, input().split(" ")))
    answer = sum(p[:K])
    tmp = sum(p[:K])
    for i in range(N - K):
        tmp = tmp + p[i+K] - p[i]
        answer = max(answer, tmp)
    print((answer + K) / 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

E = 0
prog = sum(P_E[0:K])
max = prog
for i in range(N - K):
    prog += P_E[i + K] - P_E[i]
    if prog > max:
        max = prog
    else:
        pass
    
print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
t = list(map(int,input().split()))
sum = 0

for i in range(y):
    sum += (t[i]+1)*0.5

mx = sum

for i in range(y, x):
    sum = sum + (t[i]+1)*0.5 - (t[i-y]+1)*0.5
    mx = max([sum, mx])

print(mx)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
kitaichi = []
for i in range(n):
    P = p[i]
    kitai = 1+P
    kitaichi.append(kitai)
m = [0,]
a = 0
for j in range(n):
    a += kitaichi[j]
    m.append(a)
ans = 0
for l in range(n-k+1):
    temp = m[l+k]-m[l]
    if temp> ans:
      ans = temp
print(ans/2)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

import itertools

# import math
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *P = map(int, read().split())
R = list(itertools.accumulate(P))
ans = 0
for i in range(K - 1, N):
    if i - K >= 0:
        s = ((R[i] - R[i - K]) + K) / 2
    else:
        s = (R[i] + K) / 2
    ans = max(s, ans)
print('{:.6f}'.format(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

wa = sum(p_list[0:k])
ans = wa

for j in range(n-k):
    wa = wa + p_list[j+k] - p_list[j]
    ans = max(ans, wa)
    
print(ans)

Submission status: Accepted

Solution code:
import itertools

N, K = [int(n) for n in input().split()]
P = [(int(n)+1)/2 for n in input().split()]
S = [0]+[E for E in itertools.accumulate(P)]
ans = 0
for j in range(N-K+1):
    e = S[j+K]-S[j]
    if ans < e:
        ans = e
print(ans)

Submission status: Accepted

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

''' 累積和 '''
cumulative_sum = [P[0]]
for i in range(len(P)-1):
    cumulative_sum.append(cumulative_sum[i] + P[i+1])

#入力
#print(P)
#累積和
#print(cumulative_sum)

#numpy 累積和（高速）
#import numpy
#res = numpy.cumsum(P)
#print(res)

''' 最大値探索 O(N-K) '''
#初期値
max = cumulative_sum[K-1]
max_index = 0
for i in range(N-K):
    now = cumulative_sum[K+i] - cumulative_sum[i]
    if max < now:
        max = now
        index = i
#print(max)
#print(max_index)


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

Submission status: Accepted

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

Submission status: Accepted

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

d=sum(p[:K])
ans=d
for i in range(K,N):

    d = d + p[i]-p[i-K]
    ans = max(ans, d)
   
print((ans+K)/2)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
exp=list(map(lambda x:(int(x)+1)/2,input().split())) # 入力と同時に期待値計算

l=[0]*n
sum1=0
for i in range(n):# 累積和の計算
    sum1+=exp[i]
    l[i]=sum1 

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

Submission status: Accepted

Solution code:
import numpy as np
n,k=map(int, input().split())
exp=list(map(lambda x:(int(x)+1)/2,input().split())) # 入力と同時に期待値計算

l=np.cumsum(exp) # 累積和の計算

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

Submission status: Accepted

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

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

print(max([p[j + K] - p[j] for j in range(N - K + 1)]))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
m = s = sum(p[0:k])
for p_old, p_new in zip(p, p[k:]):
  s += p_new - p_old
  m = max(m, s)
print((m+k)/2)

Submission status: Accepted

Solution code:
def func(x):
    return (x+1)/2
N, K = [int(i) for i in input().split()]
P = [func(int(i)) for i in input().split()]

# 累積和
A = [0]
for i in P:
    A.append(A[-1]+i)

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

Submission status: Accepted

Solution code:
N,K = (int(x) for x in input().split())
P = list(int(x) for x in input().split())

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

total1 = 0

for i in range(K):
    total1 += P[i]

ans = total1
total2 = 0

for i in range(N-K):

    total1 += P[K+i]
    total2 += P[i]
    
    if ans < total1 - total2:
        ans = total1 - total2


print(ans)

Submission status: Accepted

Solution code:
# ウィンドウをスライドさせる際に，期待値の全体を再計算するのをやめた
N,K = map(int, input().split())
P = [int(i) for i in input().split()]
 
expect = (sum(P[0:K])+K)/2
ma = expect
for i in range(K,N):
  expect += (P[i]-P[i-K])/2
  if ma < expect:
    ma = expect
print(ma)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
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()
now = sum(a[:k])
max = now
ans = 0
for i in range(n-k):
    now = now + a[k+i] - a[i]
    if now > max: 
        ans = i+1
        max = now
res = 0
for i in range(ans,ans+k):
    res += (a[i]+1)/2
print(res)

Submission status: Accepted

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

s = 0
for i in range(0,K):
    s = s + p[i]
t = s
for j in range(0,N-K):
    u = s + p[j+K] - p[j]
    if u > t:
        t = u
    s = u
print((t+K)/2)

Submission status: Accepted

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

num=sum(p[:k])
ans=num
for i in range(n-k):
  tmp=p[i+k]-p[i]
  num+=tmp
  if ans<num:
    ans=num

print(ans/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ps = list(map(int, input().split()))
Es = [(ps[i]+1)/2 for i in range(N)]
maxs = []
for i in range(1, N+1):
  if i<K:
    continue
  elif i==K:
    tmp = sum(Es[:i])
    maxs.append(tmp)
  else:
    tmp = tmp +Es[i-1]-Es[i-K-1]
    maxs.append(tmp)
print(max(maxs))

Submission status: Accepted

Solution code:
import sys

def LI(): return list(map(int, sys.stdin.readline().split()))
N, K = LI()
p = LI()
ps = []
for i in range(N):
    ps.append((p[i] + 1) / 2)
 
anss = []
tmp = 0
for i in range(N):
    tmp += ps[i]
    if i > K - 1:
        tmp -= ps[i - K]
    anss.append(tmp)
 
print(max(anss))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
p = LI()
ps = []
for i in range(N):
    ps.append((p[i] + 1) / 2)

anss = []
tmp = 0
for i in range(N):
    tmp += ps[i]
    if i > K - 1:
        tmp -= ps[i - K]
    anss.append(tmp)

print(max(anss))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
pi = list(map(int,input().split()))
def EV(x):
    return 1+(x-1)*0.5
for i in range(N):
    pi[i] = EV(pi[i])

ruisekiwa = sum(pi[0:K])
max_EV = ruisekiwa

for i in range(N-K):
    ruisekiwa = ruisekiwa + pi[i+K]-pi[i]
    if ruisekiwa > max_EV:
        max_EV = ruisekiwa
print(max_EV)

Submission status: Accepted

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

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

res = 0
for i in range(N - K):
	res = max(A[i + K] - A[i], res)

if N == K:
	res = A[N-1]

print( (res + K) / 2)

Submission status: Accepted

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

def avg2(x):
  result = 0
  if (x == 0):
    result = 0
  elif(x == 1):
    result = 1 * 2
  else:
    result = (1 + x)
  return result

check_ary = P[0:K]
avg2_ary = list(map(avg2, check_ary))  # 整数で扱いたいので*2している。
max2_value = sum(avg2_ary)
current_value = max2_value

for index in range(1,N - K + 1):
  # print(avg2(P[index-1 + K]))
  # print(avg2(P[index-1]))

  next_value = current_value - avg2(P[index-1]) + avg2(P[index-1 + K])
  if (max2_value < next_value):
    max2_value = next_value
  current_value = next_value # 値の更新ができていなかった。

print(max2_value/2)

Submission status: Accepted

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

#求める答えは入力をそれぞれ1足した数字の和を2で割ったものになる

#初項からk番目までの和
sum_1tok = 0
sum_k =[]
for i in range(k):
    sum_1tok += p[i]
sum_k.append(sum_1tok)
#print(sum_k)

sum_max= 0
#ひとつずつずらしてリストに格納
for i in range(1,n-k+1):
    sum_k.append(sum_k[i-1] + p[k+i-1] - p[i-1])

#print(sum_k)
#求める期待値に変換
ans = (max(sum_k) + k) /2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read

N, K, *p = map(int, read().split())

p = [(1 + i) / 2 for i in p]
p = [0] + p
P = list(accumulate(p))
answer = max(b - a for a, b in zip(P, P[K:]))

print(answer)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read

N, K, *p = map(int, read().split())

p = [(1 + i) / 2 for i in p]
p = [0] + p
P = list(accumulate(p))
answer = max(P[i] - P[i - K] for i in range(K, N + 1))

print(answer)

Submission status: Accepted

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

S = sum(P[0:K])

ans = S
for s, a in zip(P[0: N - K], P[K: N]):
    S += a - s
    ans = max(ans, S)
print(ans)

Submission status: Accepted

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

sum_k = [0] * N
tmp = 0
for i in range(K):
    tmp += p[i]
sum_k[0] = tmp
max_sum = tmp
candidate = 0
for i in range(len(p)-K):
    sum_k[i+1] = sum_k[i] - p[i] + p[i+K]
    if max_sum < sum_k[i+1]:
        max_sum = sum_k[i+1]
        candidate = i+1


ans = 0
for i in range(candidate, candidate + K):
    ans += (1 + p[i]) / 2
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate


def solve():
    N, K = map(int, sys.stdin.readline().split())
    cusum_p = (0,) + tuple(accumulate(map(int, sys.stdin.read().split())))
    return (max(i - j for i, j in zip(cusum_p[K:], cusum_p[:-K])) + K) / 2


if __name__ == "__main__":
    answer = solve()
    print(answer)

Submission status: Accepted

Solution code:
from collections import deque

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

mx = 0
s = 0
q = deque()

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

for i in range(N):
    s += p[i]
    q.append(p[i])
    if len(q) > K:
        s -= q.popleft()
    if len(q) == K:
        mx = max(mx, s)

print(mx / 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
tmp = sum(p_list[:k])
max_num = sum(p_list[:k])
for i in range(len(p_list)-k):
  tmp = tmp - p_list[i] + p_list[i+k]
  if tmp >= max_num:
    max_num = tmp
print((max_num+k)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(n) for n in input().split()]
P = [(int(n)+1)/2 for n in input().split()]
ans = sum(P[:K])
e = ans
for p,x in zip(P, P[K:]):
    e = e-p+x
    if ans < e:
        ans = e
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
E=[0]*N

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

L=[0]*(N+1)
L[0]=0

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

ans=0

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

print(ans)

Submission status: Accepted

Solution code:
def cal(a):
 	return ((1 + a) / 2)
 
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []
sum_raw = []
sum_cal = 0
 
for i in range(0, N):
    p[i] = cal(p[i])


for i in range(0, N):
	sum_cal += p[i]
	sum_raw.append(sum_cal)

for i in range(0, N - K):
	ans = sum_raw[i + K] - sum_raw[i]
	ans_raw.append(ans)

ans_0 = sum_raw[K - 1]
ans_raw.append(ans_0)

print(max(ans_raw))

Submission status: Accepted

Solution code:
def tasu(x):
    return x / 2 * (x + 1)

def kitaiti(n , k , p):

    ans = 0
    count = 0
    kitai = [0]*n
    kitaisum = [0]*n
    mod = 10**9+7

    for i in range(n):
        kitai[i] = tasu(p[i]) / p[i]

    for i in range(n):
        if i == 0:
            kitaisum[i] += kitai[i]
        else:
            kitaisum[i] += kitai[i] + kitaisum[i-1]

    for i in range(n - k + 1):

        ans = max(ans , (kitaisum[i + k - 1] - kitaisum[i-1]) if i != 0 else kitaisum[i + k - 1])

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
size, count = list(map(int,input().split()))
dices = list(map(int,input().split()))

max_sum = sum(dices[0:count])
now_sum = max_sum

for p,d in zip(dices,dices[count:]):
    now_sum = now_sum - p + d
    if max_sum < now_sum:
        max_sum = now_sum

print((max_sum+count)/2)

Submission status: Accepted

Solution code:
from itertools import accumulate

n, k = list(map(int, input().split()))
p = [0] + list(accumulate([(int(d) + 1) / 2 for d in input().split()]))

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

print(ans)

Submission status: Accepted

Solution code:
#ABC154C

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

ave = sum(p[0:k])
max = ave
for i in range(n-k):
    ave = ave-p[i]+p[k+i]
    if ave > max:
        max = ave
print(max)

Submission status: Accepted

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

Submission status: Accepted

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

P_pred = 0
for i in range(N):
  P_expect = (1+P[i])/2
  P_expect_sum[i] = P_pred + P_expect
  P_pred = P_expect_sum[i]

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

Submission status: Accepted

Solution code:
def calc(n):
    return (1 + n) / 2

def solve():
    n, k = map(int, input().split())

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

    sum = [0.0]

    for e in p:
        sum.append(sum[-1] + calc(e))

    ans = 0.0
    for i in range(k, len(sum)):
       ans = max(ans, sum[i] - sum[i - k]) 

    print(ans)

def main():
    solve()
    pass

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ex = [0 for _ in range(n)]
    for i in range(n):
        ex[i] = (p[i]+1)/2
    
    sumex = sum(ex[:k])
    tmp = sum(ex[:k])
    for i in range(n-k):
        tmp = tmp + (ex[i+k] - ex[i])
        sumex = max(sumex, tmp)
    print(sumex)
    
main()

Submission status: Accepted

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

sum_acc = [0]
tmp = 0
 
for i in range(n):
  tmp += (1 + p[i]) / 2
  sum_acc.append(tmp)

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

print(ans)

Submission status: Accepted

Solution code:
import itertools 
N,K =list(map(int,input().split()))
p =list(map(int,input().split()))
E = [0] * N

for i in range(N):
  E[i]=(p[i]+1)/2
acc = [0]
acc += list(itertools.accumulate(E))

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

print(ans)

Submission status: Accepted

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

sum_p = 0
sum_p_list =[]

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

sum_p_list.append(sum_p)

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    sum_p_list.append(sum_p)
    

ex = (max(sum_p_list) - K + 2)/2

print(ex + K - 1)

Submission status: Accepted

Solution code:
import queue
n,k=map(int,input().split())
l=list(map(int,input().split()))
el=queue.deque(maxlen=k)
ans = 0
m = 0
for i in l[:]:
    if len(el) == k:
        el.append((1+i)/2)
        m = m-m_e+el[-1]
    else:
        el.append((1+i)/2)
        m +=el[-1]
    ans = m if m>ans else ans
    m_e = el[0]
print(ans)

Submission status: Accepted

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

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

print(0.5+(0.5*ans)+(k-1)*0.5)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
def expe(n):
  return (n+1)/2
p=[expe(int(x)) for x in input().split()]
l,r=[p[0]]*(n+1),[p[n-1]]*(n+1)
for i in range(n-1):
  l[i+1]=l[i]+p[i+1]
  r[n-2-i]=r[n-1-i]+p[n-2-i]
r[n],l[n]=0,sum(p)
su=sum(p)
ans=max(su-r[k],su-l[n-k-1])
for i in range(1,n-k-1):
  sumk=su-l[i-1]-r[i+k]
  ans=max(sumk,ans)
print(ans)

Submission status: Accepted

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

num_li = [0]*n

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

num = sum(num_li[:k])
ans = num

for j in range(n-k):
    num = num-num_li[j]+num_li[j+k]
    ans = max(num, ans)

print(ans)

Submission status: Accepted

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

sum_p = 0

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

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Submission status: Accepted

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


def expected(val):
    return (val*(val+1) / 2) / val

est = sum([expected(x) for x in Ps[:K]])
max_est = est
for i in range(K, N):
    est -= expected(Ps[i - K])
    est += expected(Ps[i])
    max_est = max(max_est, est)
print(max_est)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
 
p = list(map(int, input().split()))
 
p = [(e+1) / 2 for e in p]
 
s = sum(p[0:k])
s_max = s
 
for i in range(n-k):
  s = s - p[i] + p[i+k]
  if s_max < s:
    s_max = s
    
print(s_max)

Submission status: Accepted

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

ans = [0 for _ in range(n+1)]
for i in range(n):
    ans[i+1] = ans[i]+ l[i]

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

Submission status: Accepted

Solution code:
def cal(x): return (x+1)/2

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

ans  = sum(cal(p[i]) for i in range(K))
    
cnt = ans

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=0
pp=[0]
for i in p:
    a+=i
    pp.append(a)
a=0
for i in range(k,n+1):
    a=max(a,pp[i]-pp[i-k])

print(a/2+k/2)

Submission status: Accepted

Solution code:
n, k, *p_n = map(int, open(0).read().split())
p_n.insert(0, 0)
for i in range(n):
    p_n[i + 1] = ((p_n[i + 1] + 1) / 2) + p_n[i]

exp_sum = [0] * (n - k + 1)
for i in range(n - k + 1):
    exp_sum[i] = p_n[i + k] - p_n[i]
    
print(max(exp_sum))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:k])
m = s
for i in range(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:
s = list(map(int, input().split()))
n=s[0]
k=s[1]
s = list(map(int, input().split()))
ep=[]
for i in s:
    ep.append((1+i)/2)
s={}
s[k-1]=0
for i in range(k):
    s[k-1]+=ep[i]
for i in range(k-1,n-1):
    s[i+1]=s[i]+ep[i+1]-ep[i-k+1]
print(max(s.values()))

Submission status: Accepted

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

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

rui_kitai = [kitai[0]]

for i in range(1, n):
    ruiseki=rui_kitai[i-1]+kitai[i]
    rui_kitai.append(ruiseki)

gokei = 0

for i in range(n-k+1):
    if i==0:
        wa = rui_kitai[k-1]
    else:
        wa = rui_kitai[i+k-1]-rui_kitai[i-1]
    if gokei < wa:
        gokei = wa

print(gokei)

Submission status: Accepted

Solution code:
def cal_expe(x):
  ret = (1 + x) / 2
  return ret

N,K = map(int, input().split())
data = [int(i) for i in input().split()]
sma = 0
for i in range(N):
  data[i] = cal_expe(data[i]) + sma
  sma = data[i]
max_score = data[K-1]
for i in range(K-1,N):
  pro = data[i] - data[i-K]
  if pro > max_score:
    max_score = pro
print(max_score)

Submission status: Accepted

Solution code:
import numpy as np

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

begin = 0
till = K

max = np.sum(p[0:K])
partial = max
for i in range(N-K):
    partial = partial - p[begin] + p[till]
    if(max < partial):
        max = partial

    begin += 1
    till += 1

print((max + K) / 2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
P = pow(1 / 6, K)

now = sum(map(lambda a: a * (a + 1) // 2 / a, A[:K - 1]))
ans = 0
for left, right in zip(A, A[K - 1:]):
    now += right * (right + 1) // 2 / right
    ans = max(ans, now)
    now -= left * (left + 1) // 2 / left

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

Submission status: Accepted

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


E = [0] * 1001

total = 0
for i in range(1, 1001):
    total += i
    e = total / i
    E[i] = e

P_to_E = [E[p] for p in P]


candidate = sum(P_to_E[:k])
candidates = [candidate]

for i in range(n-k):
    drop = P_to_E[i]
    add = P_to_E[i+k]
    candidate += add - drop
    candidates.append(candidate)

print(max(candidates))

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
p = list(map(int, input().split()))
e = []
ans = 0

def getExp(n):
    return (n*(n+1)/2) / n

for i in range(n):
    e.append(getExp(p[i]))

s = [0] + list(itertools.accumulate(e))

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())
p_list = [int(i) for i in input().split()]

p_list = [0] + p_list

cum_list = []
p_sum = 0
for p in p_list:
    p_sum += p
    cum_list.append(p_sum)
    
cum_list = np.array(cum_list)
sum_list = cum_list[k:]-cum_list[:-k]
index = np.argmax(sum_list)

kitaichi = k/2 + sum_list[index]/2

print(kitaichi)

Submission status: Accepted

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

total = [0]
for i in range(1, 200000):
    total.append(total[i-1]+i)

ans_index = 0
cur = sum(p[0:k])
max_p = cur
for i in range(n-k+1):
    cur = cur + p[i+k-1] - p[i-1]
    if cur > max_p:
        max_p = cur
        ans_index = i
ans = 0
for i in range(k):
    ans += total[p[ans_index+i]] / p[ans_index+i]
print(ans)

Submission status: Accepted

Solution code:
import numpy
N, K = map(int, input().split())
p = numpy.array(list(map(int, input().split())))
P = []
nowsum = 0
for p1 in p:
    nowsum += p1
    P.append(nowsum)

max = 0
nowsum = 0
for i in range(N-K+1):
    if i == 0:
        temp = P[K-1]
    else:
        temp = P[i+K-1]-P[i-1]
    if max < temp:
        max = temp
        maxno = i
exsum = 0
for i in range(K):
    temp = p[i+maxno]
    exsum += (0.5*temp*(temp+1))/temp
print(exsum)

Submission status: Accepted

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

cusum = [0.0] * ( N + 1 )

for x in range( len(deme) ):
    cusum[x+1] = cusum[x] + float(( deme[x] + 1 ) / 2)

ans = 0.0
for i in range( K, len(cusum)):
    if i > 0:
        pre = i - K
        kukan = cusum[i] - cusum[i-K]
        ans = max(ans, kukan)

print(ans)

Submission status: Accepted

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

E=[0]*n #期待値=E[i]
S=[0]*(n+1) #累積和=S[i+1]=E[0]+E[1]+...+E[i](S[0]=0)

for i in range(n):
	E[i]=(1+P[i])/2
	S[i+1]=S[i]+E[i]
max=0
for i in range(k,n+1):
	if S[i]-S[i-k] > max:
		max=S[i]-S[i-k]
print(max)