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 sys
input = sys.stdin.readline
n,k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
p = tuple(p)

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

ans = 0
for j in a:
  ans += (j+1)/2
print(ans)

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()]
p = tuple(p)

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

ans = [(j+1)/2 for j in a]
print(sum(ans))

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()]
p = tuple(p)
ans = []
chk = 0
for i in range(n-k+1):
  m = sum(p[i:k+i])
  chk = max(chk,m)
  if chk == m:
    ans = [(j+1)/2 for j in p[i:k+i]]
print(sum(ans))

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()]
ans = []
chk = 0
for i in range(n-k+1):
  m = sum(p[i:k+i])
  chk = max(chk,m)
  if chk == m:
    ans = [(j+1)/2 for j in p[i:k+i]]
print(sum(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()]
ans = []
chk = 0
for i in range(n-k+1):
  m = sum(p[i:k+i])
  chk = max(chk,m)
  if chk == m:
    ans = [(j+1)/2 for j in p[i:k+i]]
print(sum(ans))

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):
    a = 0
    for j in range(K):
        a += (p[i+j] + 1) / 2
    ans = max(ans,a)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def expect(x):
    return sum(list(range(1,x+1)))/x
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
table = []
for i in range(n-k+1):
    w = 0
    for j in range(k):
        w += expect(p[i+j])
    table.append(w)
print(max(table))

Submission status: Time Limit Exceeded

Solution code:
def expect(x):
    return sum(list(range(1,x+1)))/x
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    table = []
    for i in range(n-k+1):
        w = 0
        for j in range(k):
            w += expect(p[i+j])
        table.append(w)
    print(max(table))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def expect(x):
    return sum(list(range(1,x+1)))/x
n, k = map(int, input().split())
p = list(map(int, input().split()))
table = []
for i in range(n-k+1):
    w = 0
    for j in range(k):
        w += expect(p[i+j])
    table.append(w)

print(max(table))

Submission status: Time Limit Exceeded

Solution code:
def s2(n):return [input() for x in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
p=n1()

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

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

Submission status: Time Limit Exceeded

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
p=n1()

from collections import deque
e=deque()
for x in p:
    e.append((1+x)/2)
d=deque()
ans=0
while True:
    d.append(e.pop())
    if len(d)==k:
        ans=max(ans,sum(list(d)))
        d.popleft()
    if len(e)==0:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
p=n1()
e=[(1+x)/2 for x in p]
ans=0
for i in range(n-k+1):
    ans=max(ans,sum(e[i:i+k]))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
max_total = 0
res = 0
p = list(map(int,input().split()))
for _ in range(len(p)):
  p[_] = (p[_]+1)/2
for i in range(N-K+1):
  total = sum(p[i:i+K])
  if total >= max_total:
    max_total = total
print(max_total)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
max_total = 0
res = 0
p = list(map(int,input().split()))
for i in range(N-K+1):
  total = sum(p[i:i+K])
  if total >= max_total:
    max_total = total
    res_number = i
for j in range(res_number,res_number+K):
  res += (p[j]+1)/2
print(res)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
max_total = 0
p = list(map(int,input().split()))
for i in range(N-K+1):
  total = sum(p[i:i+K])
  if total >= max_total:
    max_total = total
    res = 0
    for j in range(i,i+K):

      res += (p[j]+1)/2
      
print(res)

Submission status: Time Limit Exceeded

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

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = 0
mx = 0

q = list()

for a in range(N):
    sm += exv[a]
    q.append(exv[a])
    if len(q) > K:
        sm -= q.pop(0)
    if len(q) == K:
        mx = max(mx,sm)

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

Submission status: Time Limit Exceeded

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

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = list()
mx = 0
for a in range(N-K+1):
    mx = max(mx,sum(exv[a:a+K]))

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

Submission status: Time Limit Exceeded

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

exv = list()

for a in p:
    exv.append((1+a)/2)

sm = list()

for a in range(N-K+1):
    sm.append(sum(exv[a:a+K]))

print('{:.12f}'.format(max(sm)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import copy
N,K = map(int, input().split())
p = list(map(int, input().split()))
que = deque([0]* K)
Max = deque([0]* K)
sumM = 0
sumq = 0
E = 0.0

for i in range(N):
    sumq -= que.popleft()
    sumq += p[i]
    que.append(p[i])
    if sumM < sumq:
        Max = copy.deepcopy(que)
        sumM = sumq
for num in Max:
    E += (num+1)* num //2/num
print(E)

Submission status: Time Limit Exceeded

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

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

for num in Max:
    E += (num+1)* num //2/num

print(E)

Submission status: Time Limit Exceeded

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

for i in range (len(p)):
    p[i]=int(p[i])
    
def f(m,p):
    q=0
    for i in range (m):
        q=q+p[i]
    return q

r=[]
for i in range (n-k+1):
    a=f(i+k,p)-f(i,p)
    r.append(a)

maxs=max(r)

print((maxs+k)/2)

Submission status: Time Limit Exceeded

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

for i in range (len(p)):
    p[i]=int(p[i])
    

maxs=0


def f(m,p):
    q=0
    for i in range (m):
        q=q+p[i]
    return q
    

for i in range (n-k+1):
    a=f(i+k,p)-f(i,p)
    if a>=maxs:
        maxs=a

print((maxs+k)/2)

Submission status: Time Limit Exceeded

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

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

for num in Max:
    E += sum(range(num+1))/num

print(E)

Submission status: Time Limit Exceeded

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

max_exp_value = 0

for i in range(n - k + 1):
  exp_value = (sum(dices[i : i + k]) + k) / 2
  if exp_value > max_exp_value:
    max_exp_value = exp_value

print(max_exp_value)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


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

kitai = []
for i in p:
    if not pd[i]:
        ex = (1 + i) / 2
        kitai.append(ex)
    else:
        kitai.append(pd[i])

ans = 0
for i in range(N):
    if i + (K-1) >= N:
        break
    else:
        ans = max(ans, sum(kitai[i:i+K]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


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

kitai = []
for i in p:
    if not pd[i]:
        dice = list(range(1, i+1))
        ex = 0
        p = 1 / len(dice)

        for x in dice:
            px = p*x
            ex += px
        pd[i] = ex
        kitai.append(ex)
    else:
        kitai.append(pd[i])

ans = 0
for i in range(N):
    if i + (K-1) >= N:
        break
    else:
        ans = max(ans, sum(kitai[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
for i in range(len(p)-K+1):
    P = p[i:i+K]
    if ans < sum(P):
        ans2 = P
    ans = max(ans,sum(ans2)) 
A = (sum(ans2)+K)/2
print(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
A = []
B = 0
C = [-1]*10000
for i in range(len(p)-K+1):
    P = p[i:i+K]
    if ans < sum(P):
        ans2 = P
    ans = max(ans,sum(ans2)) 
for j in range(len(ans2)):
  if C[ans2[j]] == -1:
      for k in range(1,ans2[j]+1):
          A.append(k)
      B += sum(A)/ans2[j]
      C[ans2[j]] = sum(A)/ans2[j]
      A = []
  else:
      B += C[ans2[j]]
print(B)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
A = []
B = 0
C = [-1]*10000
for i in range(len(p)-K+1):
    P = p[i:i+K]
    if ans < sum(P):
        ans2 = P
    ans = max(ans,sum(ans2)) 
for j in range(len(ans2)):
  if C[ans2[j]] == -1:
      for k in range(1,ans2[j]+1):
          A.append(k)
      B += sum(A)/ans2[j]
      C[ans2[j]] = sum(A)/ans2[j]
      A.clear()
  else:
      B += C[ans2[j]]
print(B)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = 0
A = []
B = 0
for i in range(len(p)-K+1):
    P = p[i:i+K]
    if ans < sum(P):
        ans2 = P
    ans = max(ans,sum(ans2))
for j in range(len(ans2)):
    for k in range(1,ans2[j]+1):
        A.append(k)
    B += sum(A)/ans2[j]
    A.clear()
print(B)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
def expected_value(li):
    def _expect(i):
        return (i+1) * (i / 2) / i
    return sum(map(_expect, li))

ans = 0

for x in range(N - K + 1):
    r = expected_value(p[x:x+K])
    if r > ans:
        ans = r
        
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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):
        ans = max(sum(p[i:i+K]), ans)

    print((ans+K)/2)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

E_sum = []
for i in range(n-k+1):
    sum_k = 0
    for j in range(i, i+k):
        sum_k += E_p[j]
    E_sum.append(sum_k)

ans = max(E_sum)
print('{:.12f}'.format(ans))

Submission status: Time Limit Exceeded

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

for i in range (len(p)):
    p[i]=int(p[i])


sums=0
maxi=0

for i in range(0,n-k+1):
    sums=0
    for t in range(i,i+k):
        sums=sums+p[t]
    if sums>=maxi:
        maxi=sums
    
print((maxi+k)/2)

Submission status: Time Limit Exceeded

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

for i in range (len(p)):
    p[i]=int(p[i])


sums=0
maxi=0

for i in range(0,n-k+1):
    sums=0
    for j in range(i,i+k):
        sums=sums+p[j]
        if sums>=maxi:
            maxi=sums
    
print((maxi+k)/2)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
an = 0
if K == 1:
  ans = (max(p)+1)/2
  print(ans)
else:
  r,l = 0,K -1
  while l <= N-1:
    su = sum(p[r:l+1])
    if su > an:
      an = su
    r += 1
    l += 1
  ans = an/2 + K/2

  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
an = 0
if K == 1:
  ans = (max(p)+1)/2
  print(ans)
else:
  for i in range(N-K+1):
    su = sum(p[i:i+K])
    if su > an:
      an = su
    if i+K+1 <= N-1:
      su -= p[i] - p[i+K+1]
  ans = an/2 + K/2

  print(ans)

Submission status: Time Limit Exceeded

Solution code:
def q4():
    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    # pが大きいほど、期待値も大きくなる
    max_sum = 0
    max_pos = 0
    for i in range(0, N-K+1):
        s = sum(P[i:(i+K)])
        if max_sum < s:
            max_sum = s
            max_pos = i

    ans = 0
    for p in P[max_pos:(max_pos + K)]:
        s = p * (p+1) / (2 * p)
        ans += s
    print('{0:.7f}'.format(ans))

if __name__ == '__main__':
    q4()

Submission status: Time Limit Exceeded

Solution code:
def q4():
    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    # pが大きいほど、期待値も大きくなる
    max_sum = 0
    max_pos = 0
    for i in range(0, N-K+1):
        s = sum(P[i:(i+K)])
        if max_sum < s:
            max_sum = s
            max_pos = i

    ans = 0
    for p in P[max_pos:(max_pos + K)]:
        s = sum([i for i in range(1,p+1)]) / p
        ans += s
    print('{0:.7f}'.format(ans))

if __name__ == '__main__':
    q4()

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
l = list(map(int, input().split()))
c = a-b+1
vector = [0]*c

for i in range(c):
	for j in range (b):
		vector[i]=vector[i]+l[i+j]
    
print((max(vector)+b)/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(max(l))

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
 
N,K = Line[0],Line[1]
 
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

diceList = [0 for _ in range(N-K+1)]
max_dice = 0
 
for i in range(N+1-K):
    diceList[i] = sum(Line[i:i+K])

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

Submission status: Time Limit Exceeded

Solution code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
 
N,K = Line[0],Line[1]
 
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
 
max_dice = 0
 
for i in range(N+1-K):
    # dices = sum(Line[i:i+K])
    dices = 0
    for z in range(K):
        dices += Line[z+i]
    # print(dices)
    if dices > max_dice:
        max_dice = dices
  
max_dice += K
 
print(max_dice/2)

Submission status: Time Limit Exceeded

Solution code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

N,K = Line[0],Line[1]

input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

max_dice = 0

for i in range(N+1-K):
    dices = sum(Line[i:i+K])
    # print(dices)
    if dices > max_dice:
        max_dice = dices

# print(max_dice)

max_dice += K

print(max_dice/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

c=[0]*len(p) #期待値

for i in range(len(p)):
  
  c[i]=((p[i]+1)*p[i])/(2*p[i])

maxev=0

for i in range(len(p)-k+1):
  ev=0
  
  for j in range(k):
    ev+=c[i+j]

  if maxev==0 or maxev<ev:
    maxev=ev

print(maxev)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
ps = list(map(int, input().split()))
ex = list(map(lambda x:(1+x)/2, ps))
sums = [sum(ex[i:i+k]) for i in range(n-k+1)]
print(max(sums))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    e = [sum(range(num+1))/float(num) for num in p]
    max_v = float('-inf')
    for i in range(N-K+1):
        exp = sum(e[i:i+K])
        max_v = max(max_v, exp)
    print(max_v)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
num_list = list(map(int , input().split()))
candidate = []
tmp = [0]
num = 0
for i in range(n):
    i += num
    
    if sum(tmp) < sum(num_list[i:i+k]):
        tmp = num_list[i:i+k]
    else:
        candidate.append(tmp)
        num += 2
        
    if i == n-k:
        candidate.append(tmp)
        break
        
ans = 0
for i in candidate:
    tmp = 0
    for j in i:
        tmp += (j+1)/2
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

mx = []

for i in range(N-K+1):
    mx.append(sum(p[i:i+K]))

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

Submission status: Time Limit Exceeded

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

E = []
mx = 0

for i in range(N-K+1):
    a = (sum(p[i:i+K])+K)/2
    if a>mx:
        mx=a

print(mx)

Submission status: Time Limit Exceeded

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

E = []

for i in range(N-K+1):
    E.append((sum(p[i:i+K])+K)/2)

print(max(E))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from operator import add
from functools import reduce


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

index = 0
total = 0
top = 0

for i in range(N-K+1):
    for j in range(K):
        total += P[i+j]

    if total > top:
        top = total
        index = i

    total = 0

expected_value = 0

for k in range(K):
    expected_value += reduce(add, range(1, P[index+k]+1)) / P[index+k]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0
e = [0] * 1001
for i in range(1, 1000 + 1):
    sum += i
    e[i] = sum / i
    # print(i, e[i])

maxV = 0
maxI = 0
for i in range(N-K+1):
    tmp = 0
    for j in range(i, i+K):
        tmp += p[j] 
    if tmp > maxV:
        maxV = tmp
        maxI = i

ans = 0
for i in range(maxI, maxI + K):
    ans += e[p[i]]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x,y = map(int,input().split())
li = list(map(int,input().split()))
from collections import deque
l = []
for i in range(len(li)):
    l.append((1+ li[i])/2)
M = 0

for i in range(len(l)-y+1):
    ll = l[i:i+y]
    m=0
    for k in range(y):
        m += ll[k]
    if m > M:
            M = m
print(M)

Submission status: Time Limit Exceeded

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

def exp_k(n):
    exp_list = []
    for i in range(n):
        exp = (P[i] * (P[i] + 1) / 2) / P[i]
        exp_list.append(exp)
    return exp_list

exp_max = 0
a = exp_k(n)
for i in range(n-k+1):
    exp_sum = sum(a[i:(i+k)])
    if exp_max < exp_sum:
        exp_max = exp_sum
        
print(exp_max)

Submission status: Time Limit Exceeded

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

def exp_k(s, k):
    exp_sum = 0
    for i in range(s, s+k):
        exp = (P[i] * (P[i] + 1) / 2) / P[i]
        exp_sum += exp
    return exp_sum

exp_max = 0
for i in range(n-k+1):
    a = exp_k(i, k)
    if a > exp_max:
        exp_max = a
print(exp_max)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np
exps = np.array(p) / 2 + 0.5

m = 0
for i in range(0, n - k + 1):
    tmp = exps[i:i + k].sum()
    if tmp > m:
        m = tmp
print(m)

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):
  check=sum(p[i:i+k])
  ans=max(ans,check)
print(ans/2+k/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
lst = []
for x in P:
  res = 0
  for y in range(x):
    c = 1/x
    res += (y+1)*c

  lst.append(res)

s = [0] 
s[0] = 0
for i in range(0, N):
  s.append(s[i] + lst[i])

res = -1
for i in range(N-K+1):
  sum = s[i+K]-s[i]
  res = max(res, sum)

print("{:.6f}".format(res))

Submission status: Time Limit Exceeded

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

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

def allsum(x):
  return x * (x+1) // 2

ans = 0
for j in range(K):
  ans += allsum(p[n+j]) / p[n+j]
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, k = MAP()
p = LIST()
psum = [0 for _ in range(n - k + 1)]
for i in range(n - k + 1):
    for j in range(i, i + k):
        psum[i] += (p[j] + 1) / 2
print(max(psum))

Submission status: Time Limit Exceeded

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

max_sum_val = 0
sum_list = []
for j in range(len(p) - K + 1):
    max_sum_val = max(sum(p[j:K+j]), max_sum_val)
print((max_sum_val + K)/2)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p =[int(s) for s in input().split()]
s = 0
key = 0
pred = 0
for r in range(n-k+1):
    s2 = sum(p[r:r+k])
    if s2>s:
        s = s2
        key = r
print(0.5*(s+k))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p =[int(s) for s in input().split()]
s = 0
key = 0
pred = 0
for r in range(n-k+1):
    s2 = sum(p[r:r+k])
    if s2>s:
        s = s2
        key = r
for f in p[key:key+k]:
    pred+=(f+1)*0.5
print(pred)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = (int(x) for x in input().split())
p1 = np.array(list(map(int, input().split())))
p2 = np.array([np.sum(p1[i:i+K]) for i in range(N-K+1)])
max = np.amax(p2)
print((max+K) / 2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = (int(x) for x in input().split())
p1 = np.array(list(map(int, input().split())))
p2 = (p1+1) / 2
p3 = np.array([np.sum(p2[i:i+K]) for i in range(N-K+1)])
print(np.amax(p3))

Submission status: Time Limit Exceeded

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

wa_temp = 0
wa_max = 0.0
wa_temp = [sum(P[i:i+K]) for i in range(N-K+1)]
print(max(wa_temp))

Submission status: Time Limit Exceeded

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

wa_temp = 0
wa_max = 0.0
for i in range(N-K+1):
    wa_temp = sum(P[i:i+K])
    if wa_max < wa_temp:
        wa_max = wa_temp
print(wa_max)

Submission status: Time Limit Exceeded

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

wa_temp = 0
wa_max = 0.0
for i in range(N-K+1):
    wa_temp = sum(P[i:i+K])
    if wa_max < wa_temp:
        wa_max = wa_temp
print(wa_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()]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(N-K+1):
  e = 0
  for j in range(i, i+K):
    e += E[j]
  if ans < e:
    ans = e
    
print(ans)