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:
q=input()
a=input()

q1=q.split(" ")
a1=list(map(int,a.split(" ")))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    bigNumber = 0

    for i in range(x-y+1):

        number = sum(p[i:i+y])

        if number > bigNumber:
            bigNumber = number

    print((bigNumber + y) / 2)

main()

Submission status: Time Limit Exceeded

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

li_kitai = list()
for l in li_p:
    li_kitai.append(sum(range(1, l + 1)) / l)

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

print(answer)

Submission status: Time Limit Exceeded

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

    bigNumber = 0

    for i in range(x-y+1):

        number = sum(p[i:i+y])

        if sum(p[i:i+y]) > bigNumber:
            bigNumber = number

    print((bigNumber + y) / 2)

main()

Submission status: Time Limit Exceeded

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

li_kitai = list()
for l in li_p:
    li_kitai.append(sum(range(1, l + 1)) / l)

answer = 0

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

Submission status: Time Limit Exceeded

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

for i in range (N - K + 1):
    x = 0
    for j in range (K):
        x += ((P[i+j]+1)/2)
        #print("i={} j={}".format(i,j))
    A.append(x)

print(max(A))

Submission status: Time Limit Exceeded

Solution code:
#ABC154D
import sys

n, k = map(int, sys.stdin.readline().split())
p = list(map(int, sys.stdin.readline().split()))

ans = 0
total = 0
for i in range(n+1-k):
    total = 0
    for j in range(k):
        total += (1+p[i+j])/2
    if ans < total:
        ans = total
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC154D
import sys

n, k = map(int, sys.stdin.readline().split())
p = list(map(int, sys.stdin.readline().split()))

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

ans = 0
for i in range(k):
    ans +=(1 + p[idx + i])/2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC154D
import sys

n, k = map(int, sys.stdin.readline().split())
p = list(map(int, sys.stdin.readline().split()))
L = [0 for _ in range(n)]

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

ans = 0
for i in range(k):
    ans +=(1 + p[idx + i])/2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = input().split()
P = input().split()
max_sum = 0
for i in range(int(N)-int(K) + 1):
  sum = 0
  for k in range(i, i + int(K)):
    p = int(P[k])
    sum += (p / 2) + 0.5
    if max_sum < sum:
      max_sum = sum
print(float(max_sum))

Submission status: Time Limit Exceeded

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

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

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

s = []
for j in range (n-k+1):
    t = 0
    for h in range (k):
        t = t + q[j+h]
    s.append(t)

print (max(s))

Submission status: Time Limit Exceeded

Solution code:
#ABC154D
import sys

n, k = map(int, sys.stdin.readline().split())
p = list(map(int, sys.stdin.readline().split()))
L = [0 for _ in range(n)]
for i in range(n):
    L[i] = (1 + p[i])/2

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
max=0
M=0
for i in range(len(p)):
  if max<sum(p[i:i+K]):
    max=sum(p[i:i+K])
    M=i
i=0
ans=0
while i<=K:
  j=1
  A=0
  while j<=p[M+i]:
    A+=j/p[M+i]
  ans+=A
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

start = end = 0
MAX = 0
for i in range(n):
    dices = p[i:i+k]
    expec = 0
    for d in dices:
        expec += (((1 + d) * d) / 2) / d
    MAX = max(MAX, expec)

print(MAX)

Submission status: Time Limit Exceeded

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

start = end = 0
MAX = 0
for i in range(n):
    dices = p[i:i+k]
    expec = 0
    for d in dices:
        expec += sum([i for i in range(1, d + 1)]) / d
    MAX = max(MAX, expec)

print(MAX)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

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

#gamma = functools.partial(functools.reduce, operator.mul)
expvalcal = lambda p: ((0.5*p)*(p+1))
result = []
max_val = -1
for i in range(k, n+1): 
    expval = 0
    #print(p[i-k:i])
    for j in p[i-k:i]:
        expval += expvalcal(j)*(1/j)
    max_val = max(max_val, expval)
print(max_val)

Submission status: Time Limit Exceeded

Solution code:
import functools
import operator

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

gamma = functools.partial(functools.reduce, operator.mul)
expvalcal = lambda p: ((0.5*p)*(p+1))
result = []
for i in range(k, n+1): 
    expval = 0
    #print(p[i-k:i])
    for j in p[i-k:i]:
        expval += expvalcal(j)*(1/j)
    result.append(expval)
print(max(result))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0] * n

max_score = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0.5*(p+1) for p in p_list]

max_score = 0

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

Submission status: Time Limit Exceeded

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

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

def calc_score(score_list):
    return sum(score_list)

dice_scores = [0.5*(p+1) for p in p_list]

score_list = []

for i in range(n- k + 1):
    score_list.append(sum(dice_scores[i:i+k]))
print(max(score_list))

Submission status: Time Limit Exceeded

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

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

def calc_score(score_list):
    return sum(score_list)

dice_scores = [calc_dice_score(p) for p in p_list]

score_list = []

for i in range(n- k + 1):
    score_list.append(sum(dice_scores[i:i+k]))
print(max(score_list))

Submission status: Time Limit Exceeded

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

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

def calc_score(score_list):
    return sum(score_list)

dice_scores = [calc_dice_score(p) for p in p_list]

score_list = []

for i in range(n- k + 1):
    score_list.append(calc_score(dice_scores[i:i+k]))
print(max(score_list))

Submission status: Time Limit Exceeded

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

for i in range(n-k+1):
    l.append(sum(p[i:i+k]))
    
print((max(l)+k)/2)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

for i in range(N):
    count = 0
    for j in range(1,p[i]+1):
        count = count+j
    P[i] = count
    E[i] = count/p[i]
if N==K:
    print(sum(E))
elif K==1:
    print(max(E))
else:
    for i in range(N-K+1):
        count = 0
        for j in range(K):
            count = count+E[i+j]
        EV[i] = count
    print(max(EV))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [(p+1)/2 for p in P]
def s(i):
    return sum(P[:i])

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
AN = list(map(float, input().split()))
 
AN = np.array(AN)
def Estimator(x):
  return (x + 1)/2
 
m = np.array([])
for i in range(N-K+1):
  B = 0
  for A in AN[i:i+K]:
    B += Estimator(A)
  m = np.append(m ,B)

print(max(m))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
AN = list(map(float, input().split()))
 
def Estimator(x):
  return (x + 1) * 0.5
 
m = []
for i in range(N-K+1):
  B = 0
  for A in AN[i:i+K]:
    B += Estimator(A)
  m.append(B)
 
print(max(m))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
AN = list(map(int, input().split()))
 
def Estimator(x):
  return (x + 1)/2
 
m = []
for i in range(N-K+1):
  B = 0
  for A in AN[i:i+K]:
    B += Estimator(A)
  m.append(B)
 
print(max(m))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [(p+1)/2 for p in P]
def s(i):
    A = []
    for j in range(i):
        A.append((P[j]))
    return sum(A)

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

Submission status: Time Limit Exceeded

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

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

y = 0
z = []

for i in range(n-k+1):
    x = 0
    for j in range(i,k+i):
        x += (1 + p[j])/2
    z.append(x)
    if x > y:
        y = x


print(y)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(max_e)

Submission status: Time Limit Exceeded

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

n,k = map(int,input().split())
p = list(map(int,input().split()))
M = 0
for i in range(n-k+1):
  li = p[i:i+k]
  total = expectation(li)
  if total > M:
    M = total
print(M)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lp = []
for i in range(n-k+1):
  p = 0.0
  for j in range(k):
    a = dices[i+j]
    p += a*(a+1)/(2*a)
  lp.append(p)
  
print(max(lp))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(max(sk))

Submission status: Time Limit Exceeded

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

ans = (maxim+k)/2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc_expectation(i):
    """
    Calculate the expectation of result value of ith die.
    """
    
    p = P[i]
    expectation = (p + 1) / 2 # (p * (p + 1) / 2) / p
    return expectation
    
    
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
expectations = list(map(calc_expectation, range(len(P))))
sum_k_adjusting_expectations = [
    sum(expectations[i: i+K]) for i in range(N-K+1)
]

print(max(sum_k_adjusting_expectations))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
num_array = list(map(int, input().split()))

processed = list(map(lambda x: (1+x)/2, num_array))

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

print(max_exp)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
num_array = list(map(int, input().split()))

processed = list(map(lambda x: (1+x)/2, num_array))

expected = []
for i in range(len(num_array) - M + 1):
    expected.append(sum(processed[i:i+M]))

print(max(expected))

Submission status: Time Limit Exceeded

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

max_num = max(sum(numbers[i:i+K]) for i in range(N+1-K))
    
answer = (max_num + K) / 2
print(answer)

Submission status: Time Limit Exceeded

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

max_num = 0
for i in range(N+1-K):
  max_num = max(max_num, sum(numbers[i:i+K]))
    
answer = (max_num + K) / 2
print(answer)

Submission status: Time Limit Exceeded

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

s=0

for i in range(N-K+1):
  s_=0
  s_=sum(p[i:K+i])
  if s_>s:
    s=s_
    
print((s+1*K)/2)

Submission status: Time Limit Exceeded

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

number_sum = []
for i in range(N+1-K):
  number_sum.append(sum(numbers[i:i+K]))
    
answer = (max(number_sum) + K) / 2
print(answer)

Submission status: Time Limit Exceeded

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

s=0

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

Submission status: Time Limit Exceeded

Solution code:
inp = list(map(int,input().split()))
N = inp[0]
K = inp[1]

P = list(map(int,input().split()))
Pcount = []
res = 0
M = 0
for count in range(0,N):
    if P[count] % 2 == 0:
        res = int((P[count]+1)) * int((P[count] // 2))
    else:
        res = int((P[count]+1)) * int((P[count] // 2)) + int(P[count] // 2) + 1
    res = float(res) / float(P[count])
    Pcount.append(res)

for count in range (0,N-K+1):
    M = max(M,sum(Pcount[count:count+K]))

print(M)

Submission status: Time Limit Exceeded

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

maxvalue = 0
for i in range(N+1-K):
  number_sum = sum(numbers[i:i+K])
  if number_sum > maxvalue:
    maxvalue = number_sum
    
answer = (maxvalue + K) / 2
print(answer)

Submission status: Time Limit Exceeded

Solution code:
from numpy import *

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

s = 0
for i in range(N - K + 1):
    t = 0
    for j in range(i, i + K):
        t += p[j]
    if s < t:
        s = t
        r = 0
        for j in range(i, i + K):
            q[r] = p[j]
            r += 1

pointc = []
for i in range(K):
    point = 0
    for j in range(0, q[i]):
        point += j + 1
    
    pointc.append(point / q[i])

print(sum(pointc))

Submission status: Time Limit Exceeded

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

print(max_s)

Submission status: Time Limit Exceeded

Solution code:
hoge = input().split()
N = int(hoge[0])
K = int(hoge[1])
pattern = map(int,input().split())
pattern = list(pattern)

maximum=0

for x in range(N-K+1):
    variable=0
    for y in range(K):
        z=x+y
        variable+=pattern[z]


    if variable>maximum:
        maximum = variable
        maximize_position = x


ans =0
for y in range(K):
    ans = ans+ (pattern[maximize_position+y]+1)/2

print(ans)

Submission status: Time Limit Exceeded

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

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

Es=[]

for i in p:
    Es.append(E_cal((int)(i)))
#print(Es)
TEs_max = 0
for j in range((int)(N)-(int)(T)+1):
    sum_E=0
    for k in range((int)(T)):
        sum_E+=Es[k+j]

    if TEs_max<sum_E:
        TEs_max = sum_E
    #print(sum_E)

print(TEs_max)

Submission status: Time Limit Exceeded

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

for i in range(N):
  ans.append((nums[i]+1)/2)

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

print(M)

Submission status: Time Limit Exceeded

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

for i in range(N):
  ans.append((nums[i]+1)/2)

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

Submission status: Time Limit Exceeded

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

def sortlist(l):
    l2 = sorted(list(set(l)))
    return l2

def factorialnum(n):
    result = 0
    for i in range(1, n+1):
        result += i 
    return result

def factorialdictionary(l):
    factoriallist = [0] * len(l)
    factoriallist[0] = factorialnum(l[0])
    for i in range(1, len(l)):
        fr = factoriallist[i-1]
        for j in range(1, l[i]- l[i-1] + 1):
            fr += l[i-1] + j
        factoriallist[i] = fr
    return dict(zip(l, factoriallist))

dictionary1 = factorialdictionary(sortlist(l))
exp_list = []
for i in range(len(l)):
    e = (dictionary1[l[i]])/l[i]
    exp_list.append(e)

currentsum = sum(exp_list[0:k])
for i in range(1, n-2):
    r = sum(exp_list[i:i+k]) 
    if r > currentsum:
        currentsum = r

print(currentsum)

Submission status: Time Limit Exceeded

Solution code:
import numpy
 
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*(N-K+1)

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

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

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  for j in range(1,p[i]+1):
    ans=ans+float(j*(1/p[i]))
print(ans)

Submission status: Time Limit Exceeded

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

def factorial(g):
    res = 0
    for i in range(1, g+1):
        res += i
    return res

exp_list = []
for i in range(len(l)):
    e = (factorial(l[i]))/l[i]
    exp_list.append(e)

currentsum = sum(exp_list[0:k])
for i in range(1, n-2):
    r = sum(exp_list[i:i+k]) 
    if r > currentsum:
        currentsum = r

print(currentsum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def S(i):
    A = []
    for j in range(i):
        A.append((P[j]+1)/2)
    return sum(A)

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
def f(n):
    return (n+1)/2
p=[]
for i in P:
    p.append(f(i))
def S(n):
    return sum(p[n:n+K])
A=[]
for j in range(len(P)):
    A.append(S(j))
print(max(A))

Submission status: Time Limit Exceeded

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

res = []
mem = {}

for i in range(0, N - K + 1):
    sum = 0

    for x in p[i:i+K]:
        if x in mem:
            sum = sum + mem[x]
            continue
        g = 0
        
        for j in range(int(x)):
            g = g + ((int(j) + 1) * 1 / int(x))
        
        mem[x] = g
        sum = sum + mem[x]

    res.append(sum)

print(max(res))

Submission status: Time Limit Exceeded

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

res = []
mem = {}

for i in range(0, N - K + 1):
    sum = 0
    jjj = "".join(p[i:i+K])
    if jjj in mem:
        continue
    
    for x in p[i:i+K]:
        for j in range(int(x)):
            sum = sum + ((int(j) + 1) * 1 / int(x))  
    
    mem[jjj] = sum
    res.append(sum)

print(max(res))

Submission status: Time Limit Exceeded

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

res = []

for i in range(0, N - K + 1):
    sum = 0
    for x in p[i:i+K]:
        for j in range(x):
            sum = sum + ((j + 1) * 1 / x)  
    res.append(sum)

print(max(res))

Submission status: Time Limit Exceeded

Solution code:
query=[int(x) for x in input().split()]
N = query[0]
K = query[1]
L = list()
L = [int(x) for x in input().split()]



def prob(x):
    out = 0.0

    out = (1 / x) * (x*(x+1))/2

    return out


final = 0.0
answer=list()
for i in range(0, N):
    final=0.0
    for j in range(i, K+i):
        if K+i<=N:
            div = L[j]
            final = final + prob(div)
    answer.append(final)

print("%14.12f"%max(answer))

Submission status: Time Limit Exceeded

Solution code:
query=[int(x) for x in input().split()]
N = query[0]
K = query[1]
L = list()
L = [int(x) for x in input().split()]



def prob(x):
    out = 0.0
    for i in range(1, x + 1):
        out = out + (1 / x) * i

    return out


final = 0.0
answer=list()
for i in range(0, N):
    final=0.0
    for j in range(i, K+i):
        if K+i<=N:
            div = L[j]
            final = final + prob(div)
    answer.append(final)
print("%14.12f"%max(answer))

Submission status: Time Limit Exceeded

Solution code:
import numpy
 
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*(N-K+1)
 
for i in range(N-K+1):
  for j in range(i,i+K):
    tmp[i]=tmp[i]+p[j]

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  for j in range(1,p[i]+1):
    ans=ans+float(j*(1/p[i]))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy

N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*N
tmp2 = 0

for i in range(N):
  if len(p)<i+K:
    break
  for j in range(i,i+K):
    tmp[i]=tmp[i]+p[j]

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  for j in range(1,p[i]+1):
    ans=ans+float(j*(1/p[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=(int(x) for x in input().split())
P=list(map(int, input().split()))
S=0
for i in range(N):
    s=sum(P[i:i+K])
    S=max(S,s)
print((S+K)/2)

Submission status: Time Limit Exceeded

Solution code:
N,K=(int(x) for x in input().split())
P=list(map(int, input().split()))
S=sum(P[0:K])
for i in range(N):
    s=sum(P[i:i+K])
    S=max(S,s)
print((S+K)/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

#e=np.cumsum(n)
#print(e)
#print(e[K:],e[:-K],e[K:]-e[:-K])


max=0
for i in range(N-K+1):
    tmp = np.sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 

print((max+K)*0.5)

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 * (ans + k))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
n=np.array(n)
max=0
for i in range(N-K+1):
    tmp = np.sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 

print((max+K)*0.5)

Submission status: Time Limit Exceeded

Solution code:
N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
max=0
for i in range(N-K+1):
    tmp = sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 

print((max+K)*0.5)

Submission status: Time Limit Exceeded

Solution code:
N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
max=0
idx=0
for i in range(N-K+1):
    tmp = sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 
        idx=i

d=n[idx:idx+K]

print((sum(d)+K)*0.5)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
max=0
idx=0
for i in range(N-K+1):
    tmp = sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 
        idx=i

d=n[idx:idx+K]
tmp=0
for i in range(K):
    tmp += np.sum(np.arange(1,d[i]+1))/d[i]
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
N,K = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
max=0
idx=0
for i in range(N-K+1):
    tmp = sum(n[i:i+K]) 
    if tmp  > max:
        max=tmp 
        idx=i

d=sorted(n[idx:idx+K])
e=[0]*K
tmp=0
for i in range(K):
    tmp += sum(range(1,d[i]+1))/d[i]
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

slist = [sum(P[i:i+K]) for i in range(N-K+1)]
max_idx = np.argmax(slist)

exp = sum([(v+1)/2 for v in P[max_idx:max_idx+K]])

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()))

def expect(x):
    prob = 1 / float(x)
    return sum(np.arange(1, x+1)) * prob

p_mapped = [expect(i) for i in p]

max = 0
for i in range(len(p_mapped)-K+1):
    answer = np.sum(p_mapped[i:i+K])
    if answer >= max:
        max = answer
print(max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

expect = {}
for i in range(1, 1001):
    prob = 1 / float(i)
    expect[i] = sum(np.arange(1, i+1)) * prob

p_mapped = [expect[i] for i in p]

max = 0
for i in range(len(p_mapped)-K+1):
    answer = np.sum(p_mapped[i:i+K])
    if answer >= max:
        max = answer
print(max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

def summation(x):
    result = 0
    for i in range(x+1):
        result += i
    return result

expect = {}
for i in range(1, 1001):
    prob = 1 / float(i)
    expect[i] = summation(i) * prob

p_mapped = [expect[i] for i in p]

max = 0
for i in range(len(p_mapped)-K+1):
    answer = np.sum(p_mapped[i:i+K])
    if answer >= max:
        max = answer
print(max)

Submission status: Time Limit Exceeded

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