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:
n,k=map(int,input().split())
l=list(map(int,input().split()))

ll=[]
for i in range(n):
    ll.append((l[i]+1)*l[i]/2/l[i])

lll=[]
for i in range(n-k+1):
    lll.append(sum(ll[i:i+k]))

print(max(lll))

Submission status: Time Limit Exceeded

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

kitai = [None]*(1000+1)
for i in range(1, 1001):
    kitai[i] = (0.5*i*(i+1))/i

ans = 0
for i in range(0, N-K+1):
    temp = 0
    for j in range(K):
        temp += kitai[P[i+j]]
    if ans < temp:
        ans = temp

print(ans)

Submission status: Time Limit Exceeded

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

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

tmpmax = 0
for i in range(n-k+1):
  s = 0
  for j in range(k):
    s += E(l[i + j])
  if s >= tmpmax:
    tmpmax = s

print(tmpmax)

Submission status: Time Limit Exceeded

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

E = []
for p in P:
  E.append(p*(p+1)/2/p)
  
ans = 0.0
for i in range(K,N+1):
  if sum(E[i-K:i])> ans:
    ans = sum(E[i-K:i])
print(float(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def expected_value(x):
    return 0.5*(x+1)

n, m = map(int, input().split())

candidates = np.array(list(map(int, input().split())))
s = np.convolve(0.5*(candidates+1), np.ones(m), mode='valid')
print(s.max())

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

l2 = list(map(E, l))

m = 0
for i in range(len(l2)-(K-1)):
    if m < sum(l2[i:i+K]):
        m = sum(l2[i:i+K])
print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
es = [(p+1)/2.0 for p in map(float, input().split())]
dp = 0
for i in range(n-k+1):
  dp = max(dp, sum(es[i:i+k]))
print(dp)

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):
    tmp = 0
    for j in range(k):
        tmp += p[i+j]*(p[i+j]+1)/(2*p[i+j])
    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()))

p2 = [0 for i in range(len(p))]
for i,px in enumerate(p):
  p2[i] = (px+1)/2

max_ans = 0
for i in range(0, N-K+1):
  ans = sum(p2[i:i+K])
  if ans > max_ans:
    max_ans = ans
    
print(max_ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))

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

print((ans + k) / 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,k=mii()
arr=limii()
aa=[]
for i in range(n):
    arri=arr[i]
    aa.append((arri*(arri+1)//2)/arri)

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

print(chk)

Submission status: Time Limit Exceeded

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

B = [0]*(N-K+1)
for i in range(N-K+1):
    B[i] = sum(p[i:i+K])

max_ind = B.index(max(B))

ep = 0
for i in range(K):
    ep += (p[max_ind+i]*(p[max_ind+i]+1))/(2*p[max_ind+i])

print(ep)

Submission status: Time Limit Exceeded

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

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

best = P[:K]
sum_best = sum(best)
last_sum = sum(P[:K])

for i in range(1,len(P)-K+1):
    box = P[i:i+K]
    sum_box = last_sum - P[i-1] + P[i+K-1]
    if sum_box > sum_best:
        best = box
        sum_best = sum_box
    last_sum = sum_box

a = 0
for i in best:
    a += get_expectation(i)
print(a)

Submission status: Time Limit Exceeded

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

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

print(a)

Submission status: Time Limit Exceeded

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

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

def get_expect(i, p):
    return 1.0 * s(p) / p

tl = []
for i in range(N - K + 1):
    t = sum([
        get_expect(i + j, p)
        for j, p in enumerate(P[i:i + K])
    ])

    tl.append(t)

print(max(tl))

Submission status: Time Limit Exceeded

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

DP=[float("inf")]*1001
for i in P:
    if DP[i]==float("inf"):
        DP[i]=(i*(i+1)//2)/i
    K.append(DP[i])

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

Submission status: Time Limit Exceeded

Solution code:
def expected_value(me):
  return ((1/2)*me*(me+1))/me

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

kaisu = n-k + 1
res = 0
for j in range(kaisu):
  temp = 0
  for jj in range(k):
    temp += expected_value(p[jj + j])
  res = max(res, temp)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
p=list(map(int,input().split()))
mx = 0
p=np.array(list(map(lambda x: (1+x)/2, p)))
#print(p)
for i in range(N-K+1):
  s = np.sum(p[i:i+K])
  #print(s)
  mx = max(s,mx)
  
print(mx)

Submission status: Time Limit Exceeded

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 += sum(range(1,A[i]+1))/A[i]
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
input_s = [input() for i in range(2)]
n, k = list(map(int,input_s[0].split()))
p_list= list(map(int,input_s[1].split()))
q_list = [(x + 1) / 2 for x in p_list]
print(max([sum(q_list[x:x+k]) for x in range(n - k + 1)]))

Submission status: Time Limit Exceeded

Solution code:
S_n = lambda n:n*(n+1)//2

def solve():
  N,K = map(int, input().split())
  P = list(map(int, input().split()))
  Q = P[:K]
  Q_ = P[:K]
  sum_Q = sum(Q)
  sum_Q_ = sum(Q)
  for i in range(N-K):
    sum_Q_ = sum_Q_ - Q_[0] + P[K+i]
    Q_ = Q_[1:]+[P[K+i]]

    if sum_Q < sum_Q_:
      Q = Q_
      sum_Q = sum_Q_

  # print(Q)

  print(sum(S_n(q)/q for q in Q))
  
solve()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split()) 
P = list(map(int,input().split()))
max_index = 0
max_size = 0
for i in range(N-K+1):
    sum_3 = sum(P[i:i+K])
    if sum_3 > max_size:
        max_index = i
        max_size = sum_3
expect = 0
for j in range(K):
    X = P[max_index+j]
    expect += (X+1)*X/(2*X)
print(expect)

Submission status: Time Limit Exceeded

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

for i in range(k,n+1):
  p = l[i-k:i]
  for j in range(k):
    s += int(0.5*p[j]*(p[j]+1))/p[j]
  
  ans.append(s)
  s=0
  
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
[n,k] = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
ls = [0]
ex = [0]
mx = 1001
for i in range(1,mx):
    ls.append(i + ls[i-1])
for i in range(1,mx):
    ex.append(ls[i]/i)
a = []
for i in range(n):
    a.append(ex[p[i]])
#print(a)
ans = -1
for i in range(n-k+1):
    ans = max(ans,sum(a[i:i+k]))
print(ans)

Submission status: Time Limit Exceeded

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

max_dice = 0
for i in range(K-1, N):
    tmp_dice = 0
    for i in range(i - K + 1, i + 1):
        tmp_kitai = 0
        for j in range(p[i]):
            tmp_kitai += (j + 1)
        tmp_kitai = tmp_kitai / p[i]
        tmp_dice += tmp_kitai
    if tmp_dice > max_dice:
        max_dice = tmp_dice
print(max_dice)

Submission status: Time Limit Exceeded

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

maxsum = -1
for i in range(0, N-K+1):
    tmp = sum([(j+1)/2 for j in P[i:i+K]])
    if tmp > maxsum:
        maxsum = tmp

print(maxsum)

Submission status: Time Limit Exceeded

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

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

mysum = 0

for i in range(N-K+1):
    if mysum < sum(mylist[i:i+K]):
        mysum = sum(mylist[i:i+K])
        myans = 0
        for j in range(i,i+K):
            myans += (mylist[j] + 1)/2 
            #print(myans)
#print(mysum,myans)
print(myans)

Submission status: Time Limit Exceeded

Solution code:
x, y = map(int,input().split())
li = list(map(int, input().split()))

a = 0
ans = 0
for i in range(x-y+1):
    for j in range(i,i+y):
        a += li[j]*(li[j]+1)//2/li[j]
        #print(a,i,j)
    ans = max(ans,a)
    a = 0
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

max = 0
for n in range(N):
  if(n+K <= N):
    sum = 0
    for k in range(K):
      sum += 0.5 * (p_list[n+k]+1)
      if(sum > max):
        max = sum
print(max)

Submission status: Time Limit Exceeded

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

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

max = 0


for i in range(n):
    sum=0
    kitai=0
    if i+k<=n:
        for j in range(i,i+k):
         sum = sum + p[j]*(p[j]+1)/2
         kitai = kitai + sum/p[j]
         sum=0
    if kitai > max:
        max = kitai

print(max)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

maxpair = (-1,-1)

for i in range(N-K+1):
    ksum = sum(PP[i:i+(K)])
    if ksum > maxpair[1]:
        maxpair = (i,ksum)
        
        
mp = maxpair[0]        
maxrange = PP[mp:(mp+K)]

esum = 0
for m in maxrange:
    esum += (m+1)/2
    
print(esum)

Submission status: Time Limit Exceeded

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

def main():
    n,k = map(int, input().split())
    l = list(map(int, input().split()))
    out = 0

    for i in range(len(l)-(k-1)):
        result = 0
        for j in range(k):
            result += sum(range(l[i+j]+1))/l[i+j]

        if out < result:
            out = result

    print(out)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline

N, K = map(int, readline().split())
p = np.array(list(map(int, readline().split())))
q = np.convolve(p, np.ones(K), mode='valid')

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

Submission status: Time Limit Exceeded

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

ls = []
for i in range(n):
    ans = 0
    for l in range(p[i]):
        ans += (1/p[i]*(l+1))
    ls.append(ans)
    
al = []
for i in range(n-k+1):
    ans = 0
    for j in range(k):
        ans += ls[i+j]
    al.append(ans)
    
print(max(al))

Submission status: Time Limit Exceeded

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

mydata = []

for i in p_L:
    kitai = sum(list(range(1,i+1)))/i
    mydata.append(kitai)

res = [0] * (n+1)

res[0] = mydata[0]
for i in range(len(mydata)-1):
    res[i+1] = res[i] + mydata[i+1]

# print(mydata)
# print(res)
# print("----")
ans = 0
for i in range(n-k+1):
    ans = max(ans,sum(mydata[i:i+k]))
    #print(mydata[i:i+k])
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

def expect(n):
    res = 0
    for i in range(1, n+1):
        res += i
    res /= n
    return res

p = list(map(expect, p))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
E = []
for i in range(0,len(p)):
    E.append((p[i]+1)/2)
def maxexp(p,E,K):
    s = 0
    for i in range(0,len(p)-K+1):
        t = 0
        for j in range(0,K):
            t = t + E[i+j]
        s = max(s,t)
    return s
print(maxexp(p,E,K))

Submission status: Time Limit Exceeded

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

ans = 0

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

print(float(ans))

Submission status: Time Limit Exceeded

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

M = [sum(P[i:i+K]) / 2 + K/2 for i in range(N-K+1)]

print(max(M))

Submission status: Time Limit Exceeded

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

maxx = 0
def total(x):
    return int(x*(x+1)/2)

kitai_P = [total(x)/x for x in P]

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int, input().split())
    pi = list(map(int, input().split()))
    max_num = 0
    new_pi = [0] * N

    for i in range(N):
        new_pi[i] += (1+pi[i])/2

    for i in range(N):
        s = sum(new_pi[i:i+K])
        if s > max_num:
            max_num = s

    print(max_num)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N_K = LIST()
P = LIST()

N = N_K[0]
K = N_K[1]

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

ans = 0
for i in max_list:
    ans += (1 + i) / 2
print(ans)

Submission status: Time Limit Exceeded

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

def E(x):
    ans = 0
    for i in range(1,x+1):
        ans += (1/x)*i
    return ans
ans = 0
for i in range(len(P)):
    P[i] = round(E(P[i]),2)

max_v = tmp = sum(P[:k])
l = 0
r = k
for i in range(1,len(P)-k+1):
    tmp = tmp-P[i-1]+P[r]
    max_v = max(max_v, tmp)
    r += 1
print(max_v)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#D
import numpy as np

N, K = map(int, input().split())
P = list(map(int, input().split()))
P = np.array(P)
ans = 0

for i in range(0, N-K+1):
    sum_P = np.sum(P[i:i+K])
    ans = max(ans, K+0.5*(sum_P-K))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
ans=sum(P[:K])/2+0.5*K
for i in range(N-K+1):
    _sum=sum(P[i:i+K])/2+0.5*K
    if ans<_sum:
        ans=_sum
print(ans)

Submission status: Time Limit Exceeded

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

max_set = [0]
for i in range(n-k+1):
    pair = []
    for j in range(k):
        pair.append(p[i+j])
    if sum(max_set) < sum(pair):
        max_set = copy.copy(pair)

ans = 0
for i in max_set:
    ans += (i+1)/2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,k=mii()
arr=limii()
aa=[]
for i in range(n):
    arri=arr[i]
    aa.append((arri*(arri+1)//2)/arri)

chk=0
for i in range(n-k+1):
    if chk < sum(aa[i:i+k]):chk=sum(aa[i:i+k])

print(chk)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def expected_value(list):
  exp_list = []
  for i in range(len(list)):
    sum = list[i]*(list[i]+1)/2
    exp = sum/list[i]
    exp_list.append(exp)
  return exp_list

ans = 0
for i in range(N-K+1):
  exp_list = expected_value(p[i:i+K])
  exp = sum(exp_list)
  if exp >= ans:
    ans = exp
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

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


@lru_cache(maxsize=None)
def calc_exp(n: int):
    return sum(range(1, n + 1)) / n


exp = -1
for i in range(len(P)):
    if len(P[i:i + K]) == K:
        e = sum(map(calc_exp, P[i:i + K]))
        if e > exp:
            exp = e

print(exp)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=list(map(int,input().split()))
a=(np.array(list(map(int,input().split())))+1)/2
  
ans=0
for i in range(n-k+1):
  tmp=np.sum(a[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()))

# １からNまでの値をもつサイコロを振ったときの期待値
def ex(x:int):
    return (x*(x+1)/2)/x

wa=0
saidai_p=0
for i in range(len(p)-(k-1)):
    if sum(p[i:i+k]) >= wa:
        wa=sum(p[i:i+k])
        saidai_p=i

kitaichi_list=[]
for i in range(k):
    kitaichi_list.append(ex(p[saidai_p+i]))

print (sum(kitaichi_list))

Submission status: Time Limit Exceeded

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

m=0
li=0
an=0

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

for j in range(k):
    an+=(p[li+j]*0.5)+0.5

print(an)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int,input().split())
plst = list(map(int,input().split()))
pnp = np.array(plst)
pnp = (pnp+1)/2
pnp2 = np.append(np.copy(pnp),[0]*(k-1))
for i in range(1,k):
  pnp2 = pnp2+ np.append(np.append([0]*i,pnp),[0]*(k-i-1))
print(max(pnp2))

Submission status: Time Limit Exceeded

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

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

_max_sum = 0
point = 0
for i in range(n-k+1):
    _sum = sum(p[i:i+k])
    if _sum >= _max_sum:
        _max_sum = _sum
        point = i

expected = 0
for i in p[point:point+k]:
    expected += 1 + 0.5 * (i - 1)
print(expected)

Submission status: Time Limit Exceeded

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

a = np.array(a)

e = a*0.5 + 0.5
ans = 0

for i in range(n-d+1):
  Sum = sum(e[i:i+d])
  
  if Sum >= ans:
    ans = Sum
  else:
    pass
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    l = []
    for i in range(K):
        l.append(p[i]+1)
    ans = sum(l)
    for i in range(K, N):
        l.append(p[i]+1)
        tmp = sum(l[-K:])
        if ans < tmp:
            ans = tmp
    print(ans/2)
resolve()

Submission status: Time Limit Exceeded

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

result = 0
expected_list = []
for p in Ps:
    temp = (p * (p + 1) / 2 )/ p
    expected_list.append(temp)

for i in range(n-k+1):
    temp = expected_list[i:i+k]
    temp = sum(temp)
    result = max(result, temp)

print(result)

Submission status: Time Limit Exceeded

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

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

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

print(cnt)

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):
 sp=0
 for j in range(i,i+k):
  sp+=((p[j]*(p[j]+1))*0.5)*(1/p[j])
# sp/=100
 ans=max(ans,sp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
import numpy as np
p = np.array(p)
p = (p + 1)/2
ans = -1
for i in range(N-K+1):
  a = np.sum(p[i:i+K])
  if a > ans:
    ans = a
print(ans)

Submission status: Time Limit Exceeded

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

l = 0
r = k

result = 0.0
while r != len(p)+1:
  this_res = 0.0
  # 期待値の計算
  for pi in p[l:r]:
    this_res += pi / 2 + 1/2
  result = max(result, this_res)
  l += 1
  r += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import math
    n,k = map(int, input().split())
    p = list(map(int, input().split()))
    p2 = [0 for i in range(n)]
    p3 = [0 for i in range(n)]
    ans=[]
    for i,j in enumerate(p):
        p2[i] = [_ for _ in range(1,j+1)]
    for i,j in enumerate(p2):
        p3[i] = sum(j)/p[i]
    for i in range(n-k+1):
        tmp = 0
        for j in range(k):
            tmp += p3[i+j]
        ans.append(tmp)
    print(max(ans))

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = 0
r = k - 1
ans_list = []
for i in range(n-k+1):
    ans = 0
    for j in range(l, r+1):
        ans += (p[j]+1) / 2
    ans_list.append(ans)
    l += 1
    r += 1

print(max(ans_list))

Submission status: Time Limit Exceeded

Solution code:
'''
.append(要素) リストに要素を追加 
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul

f = [int(s) for s in stdin.readline().rstrip().split()]
N = f[0]
K = f[1]
p = [int(s) for s in stdin.readline().rstrip().split()]
past = -2000
resNum = -2000
for el in range(N - K + 1):
    data = copy.copy(p)
    if past < sum(data[el: el + K]):
        past = sum(data[el: el + K])
        resNum = el
res = p[resNum: resNum + K]
result = 0
for el in res:
    result += (1/2+el/2)
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(len(P)):
	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 = list(map(int, input().split()))

P_extracted = [0]
for i in range(0, (n-k)+1):
    tmp = P[i:i+k]
    # print(tmp)
    if sum(P_extracted) < sum(tmp):
        P_extracted = tmp
# print(tmp)
e = 0
for i in P_extracted:
    tmp = 0
    for j in range(1, i+1):
        tmp += j / i
    # print(tmp)
    e += tmp
print(e)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc154/tasks/abc154_d
import numpy as np
N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

v = 0
idx = -1
for i in range(N):
    tmp = p[i:i + K].sum()
    if tmp > v:
        v = tmp
        idx = i

# print('v idx', v, idx)
subset = p[idx:idx + K]
ans = ((subset + 1) / 2).sum()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D
import numpy as np

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

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

ans = (ans+K)/2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
Input = list(map(int,input().split()))

N = Input[0]
K = Input[1]

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

Inp_ar = Input

for i in range(N):
  Inp_ar[i] = sum(list(range(Inp_ar[i]+1)))/Inp_ar[i]

add=0
cnt=0

for i in range(N-K+1):
  add = sum(Inp_ar[i:i+K])
  if add>cnt:
    cnt = add

print(cnt)

Submission status: Time Limit Exceeded

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

max_kitaichi = 0
max_left_n = 0
for left_n in range(N - K + 1):

    new_kitaichi = sum([(1 + pv) / 2 for pv in p[left_n:left_n + K]])

    if new_kitaichi > max_kitaichi:
        max_kitaichi = new_kitaichi

print(max_kitaichi)

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 += 1
ans = np.zeros(n-k+1)
for i in range(k):
    ans += p[i:n-k+1+i]
print(max(ans)/2)

Submission status: Time Limit Exceeded

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

#隣接する最大の部分をとって(N+1)/2すればいい

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

print((max_part+K)/2)

Submission status: Time Limit Exceeded

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,K=input_int()
P= many_int()

kitaiti = []
for p in P:
    kitaiti.append((p+1)/2 )

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

print(maxs)

Submission status: Time Limit Exceeded

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

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

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

print(max)

Submission status: Time Limit Exceeded

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

A = 0
for i in range(N-K+1):
  B = 0
  for j in range(K):
    E = 0
    for k in range(P[i+j]):
      E += k + 1
    E /= P[i+j]
    B += E
    if B > A:
      A = B

print(A)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
plist = [int(_) for _ in input().split()]
maxave = 0
for i in range(0, len(plist)-k+1):
  psub = plist[i:i+k]
  ave = (sum(psub)+k)/2
  maxave = max(maxave, ave)
print(maxave)