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: Time Limit Exceeded

Solution code:
import math
N,K=map(int,input().split())
p=list(map(int,input().split()))
sum = 0
len = 0
max = [0,0]
res = 0

for i in range(N-K+1):
    for j in range(K):
        sum = sum + p[i+j]
    if max[1] < sum :
        max[0] = i
        max[1] = sum

    sum = 0

for i in range(K):
    a = max[0]+i
    sure = p[a] * (p[a] + 1) / 2
    res = sure/p[a] + res

print(res)

Submission status: Time Limit Exceeded

Solution code:
total = 0
N,K = list(map(int,input().split()))
number_list = list(map(int,input().split()))
a = [sum(number_list[i:i+K]) for i in range(N-K+1)]
max_pattern = a.index(max(a))
print(sum(r * (1+r) / (2 * r) for r in number_list[max_pattern:max_pattern+K]))

Submission status: Time Limit Exceeded

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

def E(n):
  return sum(range(1,n+1)) / n

j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
  
else:
  flag = False
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]
          flag = True
  if flag:
    l2 = list(map(E, t))
  else:
    l2 = list(map(E, l))

  print(sum(l2))

Submission status: Time Limit Exceeded

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

sum_max = [sum(nums[i:i+k]) for i in range(n-k+1)]

max_e = (max(sum_max) +k)/2

print(max_e)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split(' '))
Pi=list(map(int,input().split(' ')))
temp=0
max=0
for i in range(N-K+1):
    temp=0
    for j in range(i,i+K):
        for pi in range(Pi[j]):
            temp+=(pi+1)/Pi[j]
    if temp>max:
        max=temp
print(max)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

loop_time = N - K

l_s = 0
l_e = K
max_score = 0
test_score = 0
# initial process
ans_list = p_list[l_s:l_e]
for j in ans_list:
    max_score += sum(range(1,j+1)) / j
    test_score = max_score
l_s = l_s + 1

for i in range(loop_time):
    # pop process
    pop_e = p_list[l_s-1]
    test_score = test_score - sum(range(1,pop_e+1)) / pop_e
    # push process
    push_e = p_list[l_e]
    test_score = test_score + sum(range(1,push_e+1)) / push_e
    if test_score > max_score:
        max_score = test_score
    l_s = l_s + 1
    l_e = l_e + 1

print(max_score)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    max_tmp = [0] * K
    for i in range(len(P) - K + 1):
        tmp = P[i: i + K]
        if sum(max_tmp) < sum(tmp):
            max_tmp = tmp

    ans = 0
    for number in max_tmp:
        ans += sum(list(range(1, number + 1))) / number

    print(ans)


resolve()

Submission status: Time Limit Exceeded

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

prev = 0
ind = 0

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

    if prev < nex:
        prev = nex
        ind = i

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int, input().split())
c=list(map(int, input().split()))
kitaichi = []
for i,v in enumerate(c):
    kitaichi.append((v/2*(v+1))/v)
score = []
for i,v in enumerate(kitaichi):
    if i+2 == len(kitaichi): break
    score.append(sum(kitaichi[i:i+k]))
print(max(score))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

p_0 = np.hstack((p, np.array([0] * (K-1))))

ps = p_0
for i in range(1,K):
    ps = ps + np.roll(p_0,i)

max = np.max(ps)

print((max + K) / 2)

Submission status: Time Limit Exceeded

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

ans4 = list()
ans2 = list()
for i in range(n - (k-1)):
    ans2.append(P[i:i+k])
    ans4.append(sum(P[i:i+k]))

am = np.argmax(ans4)
am2 = P[am:am+k]
ans = 0
for i in am2:
    for j in range(1, i + 1):
        ans += j / i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = []
for l in range(A[0]-A[1] +1):
  h = []
  for x in B[l: l + A[1]]:
    h.append((x+1)/2)
  k.append(sum(h))
print(max(k))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
#p = list(map(int, input().split()))
from sys import stdin
p = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Time Limit Exceeded

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

for i in range(N-K+1):
    kitai.append((sum((p[i:i+K]))+K)*0.5)
print('{:.12f}'.format(max(kitai)))

Submission status: Time Limit Exceeded

Solution code:
import math

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

c = n - k + 1
s = [0] * c

for i in range(c):
    l = p[i:(i+k)]
    s[i] = math.fsum(l)
    
m = s.index(max(s))
p_m = p[m:(m+k)]

exp = 0
for i in range(k):
    tmp = float(p_m[i] * (p_m[i] + 1) / 2)
    exp += float(tmp/p_m[i])
    
print(exp)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
n, k = map(int, input().split())
p = list(map(int, input().split()))
m = 0
for i in range(len(p)-k+1):
  s = sum(p[i:i+k])
  if s>m: m=s  
print((m+k)/2)
#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: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
p = list(map(int, input().split()))
temp = []
for i in range(N-K+1):
    temp.append(sum(p[i:i+K]))
iti = temp.index(max(temp))
ans = 0
for j in p[iti:iti+K]:
    ans += (j+1)/2
print(ans)

Submission status: Time Limit Exceeded

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(N - K + 1):
    for j in range(K):
        #期待値を計算してなかったら、計算
#        if(dict.get(P[i + j], -1) == -1):
#            tmp = 0
#            p = P[i + j]
#            for k in range(1, p + 1):
#                tmp = tmp + (k / p)
#            dict[p] = tmp

        li[i] = li[i] + dict.get(P[i + j])

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

Submission status: Time Limit Exceeded

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

def e(n):
    ex=(1+n)*n/(2*n)
    return ex

fst=0
for i in range(k):
    fst+=d[i]

sm2=[fst]

for i in range(n-k):
    sm2.append(sm2[i]-d[i]+d[i+k])

ansl=[]
for j in range(n-k+1):
    ans=d[j:j+k]
    ansl.append(ans)

mx=max(sm2)
ind=sm2.index(mx)

ansf=0
for y in range(k):
    ansf+=e(ansl[ind][y])
    
print(ansf)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split()) #n=10, k=4
li = list(map(int,input().split()))
value = 0
max = 0
place = []
a = 0
for i in range(n-k+1): #10 - 4 + 1 = 7
    value = (sum(li[i:i+k]))#sum(li[0:4]),sum(li[1,5])...sum(li[6:10])
    if value > max:
        max = value
        place = li[i:i+k]
for i in place:
    a += sum(range(1, i+1)) /i
print(a)

Submission status: Time Limit Exceeded

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

def E(x):
    z=1/x*(1+x)*x/2
    return z

s=0
a=N-K+1
for i in range(a):
    c=sum(p[i:(i+K)])
    if c>s:
        s=c
        k=i
z=0
for i in range(K):
    ans=E(p[k+i])
    z+=ans

print(z)

Submission status: Time Limit Exceeded

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

#check max

MX = [sum(Pi[i:i+K]) for i in range(N-K+1)]

m= max(MX)
ans= (1/2)*(m + K)
print(ans)

Submission status: Time Limit Exceeded

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

ll = []

for i in range(a-b+1):
  ll += [sum(l[i:i+b])]

ll.sort()
print(ll[-1])

Submission status: Time Limit Exceeded

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

  pp = np.array([0.5*(i+1) for i in p])
  ind =0
  m=0
  for i in range(N-K+1):
    ne = np.sum(p[i:i+K])
    if m < ne:
      ind = i
      m = ne

  print(np.sum(pp[ind:ind+K]))
main()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = [int(i) for i in input().split()]
ans = []
maxv = max(p)
dp = [i+1 for i in range(maxv+1)]
for i in range(1,maxv+1):
    dp[i] = dp[i-1]+dp[i]
dp = [j/(i+1) for i,j in enumerate(dp)]

def func(n,dp):
    ans = 0
    for i in n:
        ans += dp[i-1]
    return ans

maxv = 0
for i in range(n-k+1):
    a = func(p[i:(i+k)],dp)
    if maxv < a:
        maxv = a
    
print(maxv)

Submission status: Time Limit Exceeded

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

exp = 0e0
max = 0e0
maxi = -1


for l in range(n-k+1):
    p[l]
    exp = 0
    for m in range (l, l+k):
        exp += p[m]

    if(exp > max):
        max = exp
        maxi = l

out = 0
for aa in range (maxi,maxi+k):
    out += 0.5*(p[aa]+1)

print(out)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
max = 0.0
for i in range(n-k+1):
  sum = 0
  for j in range(k):
    d = a[i+j]
    sum += (((d+1)*d)/2)/d
  if max < sum:
    max = sum
print(max)

Submission status: Time Limit Exceeded

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

cnt=0
s=0
for i in range(n-k+1):
    tmp=p[i:i+k]
    if s < sum(tmp):
        cnt = i
        s = sum(tmp)

ans=0
for i in range(cnt, cnt+k):
    tmp=0
    ans += (1+p[i])*p[i]/2/p[i]

print(ans)

Submission status: Time Limit Exceeded

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		ret = 0
		for i in range(n+1):
			ret += i
		d[n] = ret / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

Submission status: Time Limit Exceeded

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


def kitaichi(num):
    return (sum(range(num+1)) / num)


tmp = 0
tmp_i = 0
for i in range(n-k+1):
    a = sum([p[x] for x in range(i, i+k)])
    if a > tmp:
        tmp = a
        tmp_i = i

ans = [kitaichi(p[tmp_i+x]) for x in range(k)]
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

c = np.array([sum(b[i:i+a[1]]) for i in range(0, len(b) - a[1] + 1)])
d = c.argmax()
m = c[d]

t = [np.arange(1, d + 1).sum() / d for d in range(1, m + 1)]

e = b[d:d+a[1]]
f = sum([t[d-1] for d in e])

print(f)

Submission status: Time Limit Exceeded

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

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: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
if K == 1:
  print((max(P) + 1) / 2)
  exit()
elif len(list(set(P))) == 1:
  print((P[0] + 1) / 2 * K)
  exit()

sums = []
for i in range(N - K + 1):
  sums.append(sum(P[i:i + K]))
sums.sort()
print((sums[-1] + K) / 2)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    P = [(v + 1) / 2 for v in map(int, input().split())]

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = map(int, input().split())
s = 0
sa = 0
p_exp = [(i*(i+1)/2)/i for i in p]
for i in range (N):
  if i+K-1 > N:
    break
  s = sum(p_exp[i:i+K])
  if sa < s:
    sa = s
print(sa)

Submission status: Time Limit Exceeded

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

max_pos = 0
max_value = 0
for i in range(len(P)):
    tmp_sum = sum(P[i:i+K])
#    print(i, tmp_sum, P[i:i+K])
    if tmp_sum > max_value:
        max_value = tmp_sum
        max_pos = i

#print("--------", max_pos)
total = 0
for i in range(max_pos, max_pos + K):
    total += sum(list(range(1, P[i] + 1))) / P[i]
#    print(i, total, sum(list(range(1, P[i] + 1))) / P[i])

print(total)

Submission status: Time Limit Exceeded

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

prev = 0
ind = 0

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

    if prev < nex:
        prev = nex
        ind = i

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

print(total)

Submission status: Time Limit Exceeded

Solution code:
def calcExValue(N):
    ev = []
    for i in range(1, N +1):
        ev.append(i * (1/N))
    return(sum(ev))

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

max_exv = 0

base_evs = [calcExValue(array[i]) for i in range(K)]

max_evs_sum = sum(base_evs)

for i in range(K,N):
    ev = calcExValue(array[i])
    del base_evs[0]
    base_evs.append(ev)
    if sum(base_evs) > max_evs_sum:
        max_evs_sum = sum(base_evs)
    
print(max_evs_sum)

Submission status: Time Limit Exceeded

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

def calc(n):
    return sum([i for i in range(1, n+1)]) / n

ex = []
for i in p:
    ex.append(calc(i))
max_ex = 0
for i in range(0, N-(K-1)):
    temp = sum(ex[i:i+K])
    if temp >= max_ex:
        max_ex = temp

print(max_ex)

Submission status: Time Limit Exceeded

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

#def f(x):
#    if x == 1:
#        return 1
#    else:
#        return f(x-1) + x

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

max_index = 0
max_sum = 0
for i in range(len(P)-(K-1)):
    sum_P = sum(P[i:i+K])
    if sum_P > max_sum:
        max_sum = sum_P
        max_index = i

#print(max_sum)
#print(max_index)

# 隣接したK個のリスト
kk = P[max_index:max_index+K]

# kの期待値を計算
#max_kk = max(kk)
#dp = [0]
#for i in range(1, max_kk+1):
#    dp.append(dp[i-1] + i)
#print(dp)

ans = 0
for k in kk:
    for i in range(1, k+1):
        ans += i/k
        #ans += f(k)/k

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
li = list(map(int, input().split()))
l = list()
for i in range(len(li)):
    j = i + k
    temp_li = li[i:j]
    s =  sum(temp_li)
    temp_li.insert(0, s)
    l.append(temp_li)
 
l.sort(reverse=True)
ans_li = list(l[0])
ans_li.pop(0)
 
ans = 0
for i in ans_li:
    s = sum(range(1, i+1))
    ans = ans + (s / i)
 
print(ans)

Submission status: Time Limit Exceeded

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

tmp_max = 0
tmp_pair = []
for i in range(len(p)-K+1):
    #print(p[i:i+3])
    if sum(p[i:i+K]) > tmp_max:
        # 最大値更新
        tmp_max=sum(p[i:i+K])
        # 最大値のペアを変更
        tmp_pair=p[i:i+K]
        
#print("tmp_max", tmp_max)
#print("tmp_pair",tmp_pair)

def kitaichi(dice):
    dice = range(1,dice+1)#サイコロの事象
    ex = 0#期待値を演算するための変数
    p = 1/len(dice)#サイコロの確率

    for x in dice:
        px = p*x
        ex += px

    #print("EX = ",round(ex,6))
    return round(ex,6)

print(kitaichi(tmp_max+K-1))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

P = 0
for i in range(n-k+1):
  if P < p[i:i+k].sum():
    P = p[i:i+k].sum()
    mp = p[i:i+k]

ans = 0

for i in mp:
  if i%2 == 0:
    ans += ((i+1) * i//2)/i
  else:
    ans += ((i+1) * (i//2) + (i//2) + 1)/i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ff = lambda x: int(x)+1
np_P = np.array(list(map(ff, input().split())))

v = np.array(K*[1/2])

print(np.amax(np.convolve(np_P,v, mode='same')))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    P = tuple(map(float, input().split()))
    if K == 1:
        ans = (1 + max(P)) * 0.5
    else:
        pl = [(K + sum(P[i:i+K])) * 0.5 for i in range(N-K+1)]
        ans = max(pl)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
A=[0]
for k in range(0,N-K+1):
  On=0
  for l in range(0,K):
    On+=P[k+l]
  A.append(On)

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

Submission status: Time Limit Exceeded

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

def exp(n):
    if n % 2 == 0:
        s = (n+1)*n/2
    else:
        s = (n+1)*(n-1)/2+(n+1)/2
    ans = s / n
    return ans

M = 0
for i in range(N-K+1):
    S = 0
    for j in range(K):
        S += exp(p[i+j])
    if M < S:
        M = S

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

Submission status: Time Limit Exceeded

Solution code:

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

E = []
for p in P:
    e = 0
    for i in range(1,p+1):
        e += i/p
    E.append(e)



#print(E)
ANS = s = sum(E[0:K])


for i in range(1,N-K+1):
    #sum(E[i:i+K])
    s = s+E[i+K-1]-E[i-1]
    #print(ANS, s)
    ANS = max(ANS, s)


print(ANS)

Submission status: Time Limit Exceeded

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
l=list(map(int,input().split()))
l2 = [(1+i)/2 for i in l]
kitai=0
for idx in range(n)[:n - k + 1]:
    summary=sum(l2[idx:idx + k])
    if (kitai < summary):
       kitai = summary
print(kitai)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
pl = list(map(int, input().split()))
pl_max = 0
num_max = 0
s = 0
ans = 0
for m in range(n - k + 1):
    if pl_max < sum(pl[m:m + k]):
        pl_max = sum(pl[m:m + k])
        num_max = m
for i in range(num_max, num_max + k):
    for j in range(1, pl[i] + 1):
        s += j
    ans += s / pl[i]
    s = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=np.array([0])

for i in range(k,n+1):
  p = np.array(l[i-k:i])
  if np.sum(m) < np.sum(p):
    m = p
  
print(np.sum([m[j]*(m[j]+1)/2/m[j] for j in range(k)]))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import *
from heapq import *
from fractions import gcd
import itertools
import math
import numpy as np

sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, input().split(' ')))
def In(): return int(input())
def InS(): return input()

N, K = InMap()
P = InMap()
E = [(p+1)/2 for p in P]
v = np.ones(K)
Res = np.convolve(E, v)
# Res = [sum(E[i:i+K]) for i in range(N-K+1)]
print(max(Res))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

max=0
for i in range(len(p)-K+1):
    all=np.sum(p[i:i+K])
    if all>max:
        max=all
        ind=i

a=0
for i in range(ind,ind+K):
    a+=((p[i]*(p[i]+1))/2)/p[i]

print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
p = list(map(int,input().split()))
lstp = []
for i in range(n-k+1):
    lstp.append(0.5*(sum(p[i:i+k])+k))
print("{:.10f}".format(max(lstp)))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def main(n, k, p: list):
    ans = 0

    memo = defaultdict(int)

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

        t = 0
        for j in p[i : i + k]:
            if memo[j] == 0:
                for _k in range(1, j + 1):
                    t += _k * (1 / j)
            else:
                t = memo[j]

        ans = max(ans, t)

    print("{:06f}".format(ans))


if __name__ == "__main__":
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    main(n, k, p)

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
b = input().split()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(N-K+1):
        s = sum(p[i:i+K])
        if ans < s : ans = s
    print(  (ans+K)*0.5  )
    return

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
    if K+i<=N:
            B=A[i:K+i]
            res=[]
            for b in B:
                tmp=0
                for i in range(1,b+1):
                    tmp+=(i/b)
                res.append(tmp)
    if cnt<sum(res):
        cnt=sum(res)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N-M+1):
        ans = max(ans, sum(A[i:M+i]))
    ans = (ans+M) / 2
    
    return ans

print(solve())

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
ans_temp = 0
ans_list = []
for i in range(n):
    try:
        if ans_temp < sum(p[i:i+k]):
            ans_temp = sum(p[i:i+k])
            ans_list = p[i:i+k]
    except:
        pass
ans = 0
for i in range(k):
    ans += (ans_list[i]*(ans_list[i]+1)/2)/ans_list[i]
    # print((ans_list[i]*(ans_list[i]+1)/2))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
li = list(map(int, input().split()))
l = list()
for i in range(len(li)):
    j = i + k
    temp_li = li[i:j]
    s =  sum(temp_li)
    temp_li.insert(0, s)
    l.append(temp_li)

l.sort(reverse=True)
ans_li = list(l[0])
ans_li.pop(0)

ans = 0
for i in ans_li:
    s = sum(range(1, i+1))
    ans = ans + (s / i)

print(ans)

Submission status: Time Limit Exceeded

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

  pp = [0.5*(i+1) for i in p]
  ind =0
  m=0
  for i in range(N-K+1):
    ne = sum(p[i:i+K])
    if m < ne:
      ind = i
      m = ne

  print(sum(pp[ind:ind+K]))
main()

Submission status: Time Limit Exceeded

Solution code:
num,a = map(int , input().split())

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

dol = 0
cal = 0
cnum = 0

for i in range(num - a +1):
    cal = 0
    for k in range(a):
        cal += lis[k+i]
    if dol < cal:
        dol = cal
        cnum = i

sum = 0
for p in range(a):
    sum += lis[p + cnum] * (lis[p + cnum] + 1) / (2 * (lis[p + cnum]))

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = map(int, input().split())
'''
print(N)
print(K)
print(p)
'''
s = 0
sa = 0
p_exp = [(i*(i+1)/2)/i for i in p]
'''
print(p_exp)
'''
for i in range (N):
  if i+K-1 > N:
    break
  s = sum(p_exp[i:i+K])
  if sa < s:
    sa = s
print(sa)

Submission status: Time Limit Exceeded

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

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

Max = 0
Max1 = 0
for i in range(N-K+1):
    Max1 = 0
    for k in range(i,i+K):
        Max1 += P[k]
    if Max1 > Max:
        Max = Max1
        Max1 = 0
    else:
        Max1 = 0

print(Max)

Submission status: Time Limit Exceeded

Solution code:
total = 0
N,K = list(map(int,input().split()))
number_list = list(map(int,input().split()))
a = [sum(number_list[i:i+K]) for i in range(N-K+1)]
max_pattern = a.index(max(a))
for r in number_list[max_pattern:max_pattern+K]:
    total += r * (1+r) / (2 * r)
print(total)

Submission status: Time Limit Exceeded

Solution code:
NK = [int(i) for i in input().split(" ")]
list1 = [(int(i)+1)/2 for i in input().split(" ")]
Max = 0
for j in range(NK[0]-NK[1]+1):
    if Max<sum(list1[j:j+NK[1]]):
        Max=sum(list1[j:j+NK[1]])
print(Max)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

newP = []
for i in (range(n-k+1)):
    sum_k = sum(p[i:i+k])
    newI = (sum_k + k)/2.0
    newP.append(newI)

print(max(newP))

Submission status: Time Limit Exceeded

Solution code:
all,rolls=map(int,input().split())
List=list(map(int,input().split()))

sum = 0
sumList =[]

for i in range(all - rolls + 1):
	sum = 0
	for j in range(rolls):
		sum = sum + (List[i + j] + 1) / 2
	sumList.append(sum)

sumList.sort(reverse=True)
print(sumList[0])

Submission status: Time Limit Exceeded

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

sum_max = 0
for i in range(n):
  if i+k <= n:
    sum_max = max(sum_max, sum(nums[i:i+k]))

max_e = (sum_max +k)/2

print(max_e)

Submission status: Time Limit Exceeded

Solution code:

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

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    for k in range(K):
        temp_max += P_List[j+k]
    #print(temp_max)

    if pre_max < temp_max:
        pre_max = temp_max
        max_num = j
    temp_max=0

#print('max_num:',max_num)
result = 0
for l in range(K):
    result += Kitaichi(P_List[max_num+l])

print(result)

Submission status: Time Limit Exceeded

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

max_s = 0
for i in range(N):
  if i+K < N and P[i] < P[i+K]:
    i = i + K
    continue
    
  sum_K = sum(P[0+i:K+i])
  if max_s < sum_K:
    max_s = sum_K

print((max_s+K) / 2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal

val = input().split(' ')
n = int(val[0])
k = int(val[1])

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

e_max = 0

for i in range(n - k + 1):
    temp = sum(p_list[i:k+i])
    if e_max < temp:
        e_max = temp

print(Decimal(e_max + k)/Decimal(2))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = input().split()
ex = [0 for i in range(N)]
E=0
def expectation(n):
    return (n+1)/2


for i in range(N):
    p[i] = int(p[i])
    ex[i] = expectation(p[i])


for i in range(N-K+1):
    newE = 0
    for j in range(K):
        newE += ex[i+j]

    if newE > E:
        E = newE

    

print(E)