Problem:


Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000



Sample input:
5 3
1 2 2 4 5


Sample output:
7.000000000000

Submission status: Accepted

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

exps = [(elm+1)/2 for elm in p]
#print(exps)
cum_sums = [0]*(n+1)
for ind in range(n):
  cum_sums[ind+1] = cum_sums[ind]+exps[ind]
#print(cum_sums)
k_exps = [cum_sums[ind+k]-cum_sums[ind] for ind in range(n-k+1)]
#print(k_exps)
print(max(k_exps))

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#p[i]を期待値に変更
    
p_sum=[0]*n
ans=0
for i in range(n):
    if i==0:
        p_sum[i]=p[i]
        ans=p_sum[i]
    elif i<k:
        p_sum[i]=p_sum[i-1]+p[i]
        if p_sum[i]>ans:
            ans=p_sum[i]
    else:
        p_sum[i]=p_sum[i-1]+p[i]-p[i-k]
        if p_sum[i]>ans:
            ans=p_sum[i]
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d = tuple(map(int, input().split()))
e = [0]*n

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

max1 = 0
tmp = 0
for j in range(n-k+1):
#    if len(e[j:j+k]) < k:
#        break
    if j == 0:
        tmp = sum(e[j:j+k])
    else:
        tmp = tmp - e[j-1] + e[j+k-1]
    if max1 < tmp:
        max1 = tmp
print(max1)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * 1000000
for i in range(N):
    s[i+1] = s[i] + A[i]

max_s = 0
for i in range(N):
    if max_s < s[i+K] - s[i]:
        max_s = s[i+K] - s[i]


print((max_s+K) / 2)

Submission status: Accepted

Solution code:
N,K = input().split(" ")
N = int(N)
K = int(K)
p = input().split(" ")
expected_list = []
max_list = []
for i in range(N):
  expected_list.append((int(p[i])+1)/2)
anan = 0
for j in range(K):
  anan += expected_list[j]
max_list.append(anan)
for i in range(N):
  if i == 0:
    continue
  anan = 0
  try:
    anan = max_list[i-1]-expected_list[i-1]+expected_list[i+K-1]
  except:
    pass
  max_list.append(anan)
  
print(max(max_list))

Submission status: Accepted

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

def main():
	N,K=map(int,input().split())
	#N=input().rstrip()
	#K=int(input())
	vA=list(map(int,input().split()))
	
	s = sum(vA[:K])
	res = s
	
	for p,a in zip(vA[0:], vA[K:]):
		s -= p
		s += a
		res = max(res, s)
		#print(p,a,res)
			
	#res = (A+B-1)//B
	res = (res + K)/2
	print(res)


main()

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) * i // 2 / i for i in p]
p = [0] + p
P = list(accumulate(p))
answer = 0

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,K = map(int, input().split())
    A = list(map(int,input().split()))
    P=[0]*N
    for i in range(N):
        P[i]=(A[i]+1)/2
    max=0
    check=0
            
    #for j in range(K):
    #    check +=P[j]
    check = sum(P[0:K])
    max=check
    #print(check)
    for i in range(K,N):
        check = check+P[i]-P[i-K]
        #print(i)
        #print(check)
        if check > max:
            max=check
    print(max)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
exp = sum(p[0:k])
ans = exp
for i in range(n-k):
  exp = exp-p[i]+p[i+k]
  #print(ans, exp)
  if ans<exp:
    ans = exp
    #print("ans", exp, ans)
print((ans+k)/2)

Submission status: Accepted

Solution code:
import numpy as np

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

pcm=np.concatenate([np.array([0]),(p+1).cumsum()],0)

print((pcm[K:]-pcm[0:-K]).max() /2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, t = map(int, input().split())
dices = map(int, input().split())
avg = list(map(lambda n: (n+1)/2, dices))
s = prev = sum(avg[0:t])

for i in range(1, n-t+1):
  prev = prev - avg[i-1] + avg[i+t-1]
  s = max(s, prev)
print(s)

Submission status: Accepted

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

value = 0
index = 0

for i in range(0, k):
    value += p[i]

max = value

for i in range(1, n - k + 1):
    value = value - p[i - 1] + p[i + k - 1]
    if value > max:
        max = value
        index = i

total = 0
for i in range(index, index + k):
    total += p[i] / 2 + 0.5

print(total)

Submission status: Accepted

Solution code:
import numpy as np
n, d = list(map(int, input().split()))
a = list(map(int, input().split()))
Max = 0
Sum = 0
a = np.array(a)
a = a*0.5 + 0.5
ans = []

if d == 1:
  print(max(a))
elif n == d:
  print(sum(a))
else:
  for i in range(n-d+1):
    left = a[i]
    right = a[i+d-1]

    if i == 0:
      Sum = sum(a[i:i+d])
      Max = sum(a[i:i+d])
      ans = a[i:i+d]
    else:
      Sum = Sum + right - a[i-1]

      if Sum >= Max:
        Max = Sum
        ans = a[i:i+d]
      else:
        pass

  print(sum(ans))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
dice = list(map(int, input().split()))
a=sum(dice[0:K])

l = [a]
for i in range(1,N-K+1):
    a = a - dice[i-1] + dice[K-1+i]
    l.append(a)
print((max(l)+K)/2)

Submission status: Accepted

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

p = (q + 1) /2
p = p.tolist()
a = sum(p[:K])
mx = a

for i in range(0,N-K):
    a = a - p[i] + p[i+K]
    if a > mx:
        mx = a

print(mx)

Submission status: Accepted

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

if k == 1:
  print(max(li))
else:
  a = 0
  for i in range(n-k+1):
    if i == 0:
      xe = sum(li[0:k])
    else:
      xe = xe - li[i-1] + li[i+k-1]
    a = max(a, xe)
  print(a)

Submission status: Accepted

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

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)

Submission status: Accepted

Solution code:
#At coder 2020/2/9 D
#import numpy as np

# 入力
N,K= map(int, input().split())
p = list(map(int, input().split())) 
#p2 = sorted(p, reverse=True)
#print(p2)
kk=[0] * (N-K+1)
#p=np.array(p)
kk[0]=sum(p[0:K])
for ii in range(1,N-K+1):
    kk[ii]=kk[ii-1]-p[ii-1]+p[K+ii-1]
kk=max(kk)
K=float(K)
kk=float(kk)
ans=0.5*(kk+K)

print(ans)

Submission status: Accepted

Solution code:
def solve(_list,_k):
  accumulate_list = [0.]
  for i in _list:
    accumulate_list.append((i+1)/2 + accumulate_list[-1])

  ans = -1.0
  for i in range(len(accumulate_list)-_k):
    ans = max(ans, accumulate_list[i+_k]-accumulate_list[i])
  return ans

if __name__ == "__main__":
  _n, _k = map(int, input().split())
  _l = [int(i) for i in input().split()]

  result = solve(_l, _k)
  print(result)

Submission status: Accepted

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

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

print((ans+k)/2)

Submission status: Accepted

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

Submission status: Accepted

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

# T[i]に1からiまでの合計値が入っている
# M[i]にiの目があるさいころの期待値が入っている
# T = [0]
# M = [0]
# for j in range(1,1001):
#     T.append(j + T[j-1])
#     K.append(T[j]/j)
# 計算すると(n+1)/2


# M = [0]
# for j in range(1,1001):
#     M.append((j+1)/2)
# # print(K)

# PP = []
# for k in P:
#     PP.append(M[k])
# TEMP = []
ANS = 0
for i in range(N-K+1):
    # TEMP.append(sum(P[i:i+K]))
    if i == 0:
        TEMP = sum(P[i:i+K])
    else:
        TEMP = TEMP - P[i-1] + P[i+K-1]
    if TEMP > ANS:
        ANS = TEMP
# ANS = max(TEMP)
print((ANS+K)/2)

Submission status: Accepted

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

import numpy as np

E = (np.array(P)+1)/2
E = np.cumsum(E)  

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Submission status: Accepted

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

ans = 0

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

ans = sum(num_array[0:K])
temp = ans
for i in range(1, N-K+1):
    j = i+K-1
    temp = temp - num_array[i-1] + num_array[j]
    if temp > ans:
        ans = temp

print(ans)

Submission status: Accepted

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

r = 0
c = 0
pre = [None] * len(p)

for i, x in enumerate(p):
    a = (x + 1)/2
    pre[i] = a
    c += a
    if i - K >= 0:
        c = c - pre[i - K]
    if c > r:
        r = c
print(r)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def ex(x):
    return (x+1)/2
 
n, k = map(int, input().split())
lst = list(map(int, input().split()))
source = [ex(i) for i in range(1, 1001)]
exlst = [source[l-1] for l in lst]
maxmum = -1

cumulative = [0]
total = 0
for ex in exlst:
    total += ex
    cumulative.append(total)

maxmum = -1
for i in range(n-k+1):
    sum_ = cumulative[i+k] - cumulative[i]
    if sum_ > maxmum:
        maxmum = sum_
print(maxmum)

Submission status: Accepted

Solution code:
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

sum = 0
ans = 0

for i in range(a[0]):
    sum += (1 + b[i])/2
    if i > a[1]-1:
        sum -= (1 + b[i-a[1]])/2
    if ans < sum:
        ans = sum

print(ans)

Submission status: Accepted

Solution code:
a=input().split()
N=int(a[0])
K=int(a[1])
zantei=0
P=list(map(float,input().split()))

P_ex=list(map(lambda x: (x+1)/2,P))


for i in range(0,K):
    
    zantei+=P_ex[i]
zanans=0
buffer=P_ex[0]
beforeans=zantei
for i in range(1,N-K+1):
    if(beforeans-buffer+P_ex[K+i-1]>zantei):
        zantei=beforeans+P_ex[K+i-1]-buffer
    beforeans+=(P_ex[K+i-1]-buffer)
    buffer=P_ex[i]

print(zantei)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
A = 0
for j in range(a[1]):
    A = A + b[j]
c = A
d = 0
ans = 0
if a[0] == a[1]:
    for l in range(a[0]):
        ans=ans +((b[l] + 1)/2)
else:
    for i in range(a[1],a[0]):
        B = A - b[(i-a[1])] + b[i]
        if B > c:
            d = i - a[1] + 1
            c = B
        A = B

    for k in range(a[1]):
        ans =ans + ((b[d+k] + 1)/2)

print(ans)

Submission status: Accepted

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


maxnum=0
index=0
num=0
for i in range(len(P)):
    num+=P[i]
    if maxnum<num:
        maxnum=num
        index=i




    if i>=K-1:
        num-=P[i-(K-1)]


List=[]
for i in range(K):
    x1=P[index-i]

    sumx1=(1+x1)/2
    List.append(sumx1)


print(sum(List))

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
l = [(int(i)+1)/2 for i in input().split()]

temp = sum(l[:b])
max = temp
for i in range(b,a):
  temp = temp + l[i] - l[i-b]
  if max < temp:
    max = temp
    
print(max)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(max([P_sum[i + K] - P_sum[i] for i in range(N - K + 1)]))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
total = 0
saidai = -9999
#累積和の最大値を定義します
ans = 0
B = [0]*(len(A)+1)
#Bは累積和のリスト
for i in range(len(A)):
    total += A[i]
    B[i+1] = total
    #A[i]までの合計をB[i+1]へ
for j in range(N-K+1):
     if B[j+K]-B[j]>saidai:
      #最大値比較
            saidai = B[j+K]-B[j]
            P = A[j:j+K]
          #最大値比較をしたとき、スライスをとる
for i in range(len(P)):
    ans += (0.5*P[i]*(P[i]+1))/P[i]
    #スライスをとったところの期待値を計算
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
s = 0
rs = sum(p[0:k])
ms = rs
for i in range(1, n - k + 1):
  rs = rs - p[i-1] + p[i+k-1]
  if rs > ms:
    s = i
    ms = rs

ans = 0.0
for pp in p[s:s+k]:
  ans += (1+pp)/2
print(ans)

#for i in range(len(p)-k+1):
#  s = sum(p[i:i+k])
#  if s>m: m=s  

#c = [sum(p[i:i+k]) for i in range(len(p)-k+1)]
#print(c)
#pn = np.array(p)
#v = np.array([1]*k)
#c = np.convolve(pn, v, mode='same')
#print((max(c)+k)/2)

Submission status: Accepted

Solution code:
N,K = list(map(int, input().split()))
p = list(map(int, input().split()))
max_l = 0
Max_l = p[0:K]
S = [0]
s=0
for j in range(N):
    s += p[j]
    S.append(s)

for i in range(N-K+1):
    m = S[K+i]-S[i]
    if m > max_l:
        max_l = m



print((max_l+K)/2)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

ans = c[K-1]

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

print((ans + K) / 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Max = 0
for i in range(N):
    Sum=0
    if i+K<=N:
        Sum = s[K+i] - s[i]
        if Sum > Max:
            Max = Sum
            index = i
    else:
        break
Sum=0
for i in range(K):
    kitai=1/2*p[index+i]*(p[index+i]+1)
    kitai = kitai / p[index+i]
    Sum+=kitai
print(Sum)

Submission status: Accepted

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


n, k_range = map(int, input().split())
p = list(map(int, input().split()))
e_list = [0] * n
ans_list = [0] * n
ans = 0.0

for i in range(n):
    e_list[i] = calc_expected_value(p[i])
    if i == k_range-1:
        ans_list[i] = sum([e_list[i-k] for k in range(k_range)])
    else:
        ans_list[i] = ans_list[i-1] + e_list[i] - e_list[i-k_range]

print(max(ans_list))

Submission status: Accepted

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

temp = sum(P[:k])
res = temp
for i in range(n- k):
  temp -= P[i]
  temp += P[i+k]
  res = max(res, temp)
  
ans = (res + k) * 0.5

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
e = list(map(lambda x: (1 + int(x)) / 2, input().split()))
mt = sum(e[:k])
mf = mt
for i in range(1, n - k + 1):
  mt -= e[i - 1]
  mt += e[i - 1 + k]
  if mt > mf:
    mf = mt
print(mf)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().strip().split()))
P = list(map(int, input().strip().split()))
start = 0
rec_sum = sum(P[0:K])
max_sum = rec_sum
for i in range(1, N - K + 1):
  rec_sum = rec_sum - P[i-1] + P[i+K-1]
  if rec_sum > max_sum:
    start = i
    max_sum = rec_sum
    
ans = 0.0
for _p in P[start:start+K]:
  ans += (1+_p) / 2
print(ans)
#print(P[start:start+K])

Submission status: Accepted

Solution code:
def expected_value(x):
    a = int(x)
    s = (a+1) * (a/2)
    # e = 0
    # for i in range(1, a+1):
    #     e += i / a
    return s / a

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

# initialize
left = 0
max_ev = 0
ev = 0
for i in range(k):
    ev += evs[i]

max_ev = ev
for i in range(k, n):
    ev = ev - evs[left] + evs[i]
    left += 1
    if ev > max_ev:
        max_ev = ev
print('{:.7f}'.format(max_ev))

Submission status: Accepted

Solution code:
import numpy as np
n,k=map(int,input().split())
exp=tuple(map(lambda x: (int(x)+1)/2,input().split()))
l=np.cumsum(exp)

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

Submission status: Accepted

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def moving_average(a, n=3) :
    ret = np.cumsum(a, dtype=float)
    ret[n:] = ret[n:] - ret[:-n]
    return ret[n - 1:]

def main():
    N, K = map(int, readline().split())
    p = np.array(readline().split(), dtype=np.int32)
    q = moving_average(p, K)

    print((np.max(q) + K) / 2)


main()

Submission status: Accepted

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

s = [1+0.5*(i-1) for i in range(1,max(p)+1)]

q = [0]
c = 0
for i in p:
    c += s[i-1]
    q.append(c)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

prev = sum(p[1:k])
current = sum(p[1:k])
ind = 0

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

    if prev < current:
        prev = current
        ind = i

total = 0
for i in range(ind, ind + k):
    total += p[i] / 2 + 0.5

print(total)

Submission status: Accepted

Solution code:
n,k = input().split()
n = int(n)
k = int(k)
nums = [float(i)/2+0.5 for i in input().split()]
ma = sum(nums[0:k])
now = ma
for i in range(n-k):
  now = now - nums[i] + nums[i+k]
  if now>ma:
    ma = now
print(ma)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
i = 0
kitaichi = [0] * n
kitaichi_sum = [0] * n
ans = 0
for p in input().split():
  kitaichi[i] = int(p) * (int(p)+1) / 2 / int(p)
  if i == 0:
    kitaichi_sum[i] = kitaichi[i]
  elif i >= k:
    kitaichi_sum[i] = kitaichi_sum[i-1] + kitaichi[i] - kitaichi[i-k]
    if kitaichi_sum[i] > ans:
      ans = kitaichi_sum[i]
  else:
    kitaichi_sum[i] = kitaichi_sum[i-1] + kitaichi[i]
  if kitaichi_sum[i] > ans:
    ans = kitaichi_sum[i]
  i += 1
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
  
m = sum(p[0: k])
sump = m

for i in range(1, n-k+1):
  sump = sump - p[i-1] + p[i+k-1]
  if m < sump:
    m = sump

ans = (m + k) / 2

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
li=list(map(int, input().split()))
tmp=0
for i in range(k):
  tmp+=li[i]

max=tmp
for i in range(1,n-k+1):
  tmp=tmp-li[i-1]+li[i+k-1]
  if max<=tmp:
    max=tmp
print((max+k)/2)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()
    ans = 0
    tmp = 0
    if n == k:
        k = list(accumulate(range(max(p)+1)))
        for x in p:
            ans += k[x]/x
        
        print(ans)
        sys.exit()

    p_ = list(accumulate(p))
    #print(p_)


    for i in range(n-k):
        #print(i,p_[i+k]-p_[i])
        if tmp <= p_[i+k]-p_[i]:
            l = p[i+1:i+k+1]
            tmp = p_[i+k]-p_[i]

    #print('l:',l)
    k = list(accumulate(range(max(l)+1)))

    for x in l:
        ans += k[x]/x
        
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

dp = [0]*1001
dp[0] = 0
for i in range(1000):
  dp[i+1] = i+1 + dp[i]

ans = 0.0
for i in range(ai, ai+K):
  ans += dp[p[i]]/p[i]

print(ans)

Submission status: Accepted

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

saikoro = [0] * 1001
for i in range(1, 1001):
    saikoro[i] = (saikoro[i-1] + i)

s = [0] * (n + 1)
for u in range(1,n + 1):
    s[u] = saikoro[p[u - 1]] / p[u - 1] + s[u - 1]

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
memo = sum(P[:K])
ans = memo

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

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

Submission status: Accepted

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

max_count = 0
summary = 0
 
for i in range(n-k+1):
    if i == 0:
        summary = sum(p_list[i:i+k])
    else:
        summary += p_list[i+k-1]-p_list[i-1]
    max_count = max(max_count,summary)
 
print(max_count/2 + k/2)

Submission status: Accepted

Solution code:
import numpy

n,k = map(int,input().split())
p = list(map(int,input().split()))
q = []
for i in range(n):
    q.append(((((p[i]+1)*p[i])/2)/p[i]))

res = numpy.cumsum(q)
ans = []
ans.append(res[k-1])
for i in range(k,n):
  ans.append(res[i]-res[i-k])
print(max(ans))

Submission status: Accepted

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


def solve(N: int, K: int, p: "List[int]"):
    cumsum = np.cumsum(p)
    # print(cumsum)
    max_value = 0
    index_first = 0
    for i in range(N - K):
        if max_value < cumsum[i + K] - cumsum[i]:
            max_value = max(max_value, cumsum[i + K] - cumsum[i])
            index_first = i + 1

    # print(max_value)
    # print(index_first)
    result = 0
    for j in range(K):
        idm = (p[index_first + j] / 2) * (1 + p[index_first + j])
        idm = idm / p[index_first + j]
        result += idm

    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    N,K = map(int,input().split())
    p = list(map(DE,input().split()))
    ans = 0
    tmp = [sum(p[:K])]
    for i in range(K,N):
        tmp.append(tmp[i-K]+p[i]-p[i-K])
    print(max(tmp))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

dp = [0] * (N)
dp_sub = [0] * (N)

dp[0] = (p[0] + 1) / 2
dp_sub[0] = (p[0] + 1) / 2

for i in range(1, K):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i]

for i in range(K, N):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i] - dp_sub[i-K]
    
print(max(dp))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()


memo = [0 for i in range(N - K + 1)]

def solve():
    memo[0] = sum(p[:K])
    for i in range(1, N - K + 1):
        memo[i] = memo[i - 1] + p[i + K - 1] - p[i - 1]
    index = 0
    res = 0
    for i, m in enumerate(memo):
        if res < m:
            res = m
            index = i
    ans = 0
    for i in range(K):
        ans += (p[index + i] + 1) / 2
    return ans
if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

c=0
x=0
m=sum(p[0:k])
z=m
for i in range(1,n-k+1):
#  print(z,p[i-1],p[i+k-1])
  z=z-p[i-1]+p[i+k-1]
#  print(m,z)
  if m<z:
    m=z
    x=i
#print(x)
for i in range(x,x+k):
#  print(p[i])
  c+=((p[i]*(p[i]+1))/2)/p[i]
print(c)

Submission status: Accepted

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

li = [0] * (N - K + 1)

max = max(P)
dict = {}
sumList = [0] * max

sumList[0] = 1
dict[1] = 1

for i in range(1, max):
    sumList[i] = sumList[i - 1] + (i + 1)
    dict[i+1] = sumList[i] / (i + 1)

for i in range(K):
    li[0] = li[0] + dict.get(P[i])

#一番大きな数を含む並び順を求める
for i in range(1, N - K + 1):
    li[i] = li[i - 1] - dict.get(P[i - 1]) + dict.get(P[i + K - 1])

#print(li)
print(sorted(li, reverse=True)[0])

Submission status: Accepted

Solution code:
from collections import deque


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
dices = [int(c) for c in line]

max_E = 0
expectations = deque([0] * K, maxlen=K)
e_memo = {}
E = 0
for dice in dices:
    E -= expectations.popleft()
    if e_memo.get(dice) is None:
        e_memo[dice] = sum(range(1, dice + 1)) / dice
    e = e_memo[dice]
    expectations.append(e)
    E += e
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)

Submission status: Accepted

Solution code:
def main():
    """"ここに今までのコード"""
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
p=list(map(int,input().split()))
t=0
k=sum(p[0:K])

if N==K:
  print((k+K)/2)
else:
  for i in range(N-K):
    k-=p[i]
    k+=p[i+K]
    if k>t:
      t=k
    
  print((K+t)/2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P=input().split()
P = [int(p) for p in P]
maxv=0
expv=0

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

maxv=expv

for i in range(N-K):
    expv=expv-P[i]+P[i+K]
    maxv=max(maxv,expv)
    
        
print("{:.20f}".format((maxv+K)/2))

Submission status: Accepted

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

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


wa=sum(P[0:K])
temp=sum(P[0:K])
for i in range(N-K):
    wa+=P[i+K]
    wa-=P[i]
    if temp <= wa:
        temp=wa

ans=s(temp+K-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
p=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#最大のリストを選定
before_pi = p[0]
before_sum = sum(p[0:k])+ 0.0
suml = [sum(p[0:k])]
for i in range(1,n-k+1):
    before_sum = before_sum - before_pi+p[i+k-1]
    suml.append(before_sum)
    before_pi = p[i]

#計算
print((max(suml)+k)/2.0)

Submission status: Accepted

Solution code:
x = input().split()
N = int(x[0])
K = int(x[1])

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

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

S = [0]
x = 0
for i in range(N):
    x += L[i]
    S.append(x)

E = []
if K > 1:
    for i in range(N-K+1):
        E.append(S[i+K]-S[i])
    print(max(E))
else:
    print(max(L))