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())
p=list(map(int,input().split()))
ans=0
res=[]
for i in range(n):
    if i+k>n:break
    tmp=sum(p[i:i+k])
    ans=max(ans, tmp)
    if ans==tmp:
        res=p[i:i+k]
ans=0
for j in res:
    ans+=sum(range(1,j+1))/j
print(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):
    n = p[i + j]
    a += n * (n+1)/2/n
  if a > ans:
    ans = a

print(ans)

Submission status: Time Limit Exceeded

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

ps = list(map(lambda n: (n+1)/2, ps))

mx = 0
for i in range(n - (k-1)):
  sm = sum(ps[i:i+k])
  if sm > mx:
    mx = sm
print(mx)

Submission status: Time Limit Exceeded

Solution code:
n,k =map(int,input().split())
p = list(map(int,input().split()))
kitai = []
for i in range(1,n+1):
    sum_k = 0
    for j in range(1,p[i-1]+1):
        sum_k += j *(1/p[i-1])
    kitai.append(sum_k)
ans = []
for i in range(0,n-k+1):
    sum_ans = 0
    for j in range(k):
        sum_ans += kitai[j+i]
    ans.append(sum_ans)
print(max(ans))

Submission status: Time Limit Exceeded

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

ex = [0] * n
for i in range(n):
    ex[i] += sum([j for j in range(1, p[i] + 1)]) / p[i]

ans = 0
for j in range(n - k + 1):
    sum = 0
    for z in range(j,j + k):
        sum += ex[z]
    ans = max(ans, sum)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
m=0
S=0
t=0
x=0

for i in range(N-K+1):
  for k in range(K):
    S+=p[i+k]
    if (i+k)==(i+K-1):
      if m<S:
        m=S
        t=i
      S=0

for a in range(K):
  x+=(1+p[t+a])/2

print(x)

Submission status: Time Limit Exceeded

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

m = 0
pos = 0
for i in range(n - k + 1):
    s = sum(p[i:(i+k)])
    if m < s:
        m = s
        pos = i
r = 0
for i in range(k):
    v = p[pos + i]
    s = 0
    for j in range(1, v + 1):
        s += j
    r += s/v
print(r)

Submission status: Time Limit Exceeded

Solution code:
[N,K] = [int(s) for s in input().rstrip().split(' ')]
L_A = [int(s) for s in input().rstrip().split(' ')]
if N < K:
  print("error")
elif N == K:
  print((sum(L_A) + N) / 2)
else:
  a = N - K
  p = 0
  for i in range(a + 1):
    x = 0
    for j in range(K):
      x += L_A[i + j]
    p = max(p,x)
  print((p + K) / 2)

Submission status: Time Limit Exceeded

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

n, k = int(n), int(k)

ans = 0

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


print(ans / 2)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
s_max = 0
max_i=0
ret = 0
for i in range(n-k+1):
  p_s=sum(p[i:i+k])
  if s_max<p_s:
    s_max=p_s
    max_i=i
for i in range(k):
  p_i = p[max_i+i]
  ret+=(1+p_i)*p_i/(2*p_i)
  
print(ret)

Submission status: Time Limit Exceeded

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

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

ans = 0
for p in P[idx:idx+K]:
    ans += 1/p * p * (1 + p) /2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def calc_exp(p):
    result = 0
    for n in p:
        result += expectation(n)
    return result


def expectation(p):
    n = sum(p)
    return 0.5 * n + 0.5 * len(p)


def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    max_num = 0
    max_idx = -1
    for i in range(n-k+1):
        num = sum(p[i:i+k])
        if num >= max_num:
            max_num = num
            max_idx = i
    print(expectation(p[max_idx:max_idx+k]))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

windows = []

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

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

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

max = 0
index = 0
for j in range(n-k+1):
    goukei = sum(p[j:j+k])
    if goukei > max:
        max = goukei
        index = j

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

Submission status: Time Limit Exceeded

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

n,k=map(int,input().split())
p=np.array(list(map(int,input().split())))
p=(p+1.)/2.
max_p=0

for i in range(n-k+1):
    s=np.sum(p[i:i+k])
    if  max_p < s:
        max_p=s

print(max_p)

Submission status: Time Limit Exceeded

Solution code:
hoge = input().split()

N = int(hoge[0])
K = int(hoge[1])
p_list = []

hoge = input().split()

for i in range(N):
  p_list.append(int(hoge[i]))
  
big = 0
max_idx = 0
for i in range(N-K+1):
  _sum = sum(p_list[i:i+K])
  if _sum > big:
    big = _sum
    max_idx = i
    
ans = 0
for j in range(K):
  num = p_list[max_idx+j]
  kitaichi = (float(num) / 2) + 0.5
  ans += kitaichi
print(ans)

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

def rolling_window(a, window, step_size):
    shape = a.shape[:-1] + (a.shape[-1] - window + 1 - step_size + 1, window)
    strides = a.strides + (a.strides[-1] * step_size,)
    return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)

print((max(np.sum(rolling_window(p,K,1),axis=1))+K)/2)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

calc_expectedval = (lambda p: sum(range(p+1)) / p)
expected_vals = [calc_expectedval(int(x)) for x in input().split()]

# expected_vals = [sum(range(p+1)) / p for p in ps]

maxval = 0
for i in range(n - k + 1):
  candidate = sum(expected_vals[i:i+k])
  if candidate > maxval:
    maxval = candidate

print(maxval)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

# print(p)

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

Submission status: Time Limit Exceeded

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

b=[]
for i in range(n):
  b.append((1+a[i])/2)
  
ans=0
for i in range(n-k+1):
  tmp=np.sum(b[i:i+k])
  if ans<tmp:
    ans=tmp
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
'''
期待値
E[X] = sum(1:N)/N
'''

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

# 期待値のリスト生成
ex_list = list()
for i in range(len(p)):
	ex_list.append(sum(range(1,p[i]+1))/p[i])

ans = list()
for i in range(N-K+1):
	ans.append(sum(ex_list[i:i+K]))
	# ans.append(ex_list[i:i+K])
# print(ans)
ans.sort(reverse=True)
print(ans[0])

Submission status: Time Limit Exceeded

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

for i in range(len(p)):
    p[i] = 0.5*(p[i]+1)
for i in range(k-1, len(p)):
    sum_ = 0
    for j in range(k):
        sum_ += p[i-j]
    ans = max(ans, sum_)
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
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 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 = float('inf')
mod = 10 ** 9 + 7

n, k  = MAP()
p = LIST()

def kitai(a):
    tmp = 0
    # for a in A:
    tmp = 1/a * (1/2 * a * (a+1))
    return tmp
    

ans = 0
# A = []
B = []
for i in range(n-k+1):
    A = p[i:i+k]
    B.append(A)
for A in B:
    k = 0
    for a in A:
        # print(a)
        k += kitai(a)
    ans = max(ans, k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    res = 0
    maxI = 0
    maxV = 0
    for i in range(N-K+1):
        v = sum(P[i:i+K])
        if v > maxV:
            maxV = v
            maxI = i
    res = (sum(P[maxI:maxI+K]) + K) / 2.0
    print(res)

main()

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=tuple(map(int,input().split()))
idx = 0
s=0
e=0

for i in range(n-k+1):
    s1 = sum(p[i:i+k])
    if s1 > s:
        idx = i
        s = s1

for i in range(idx,idx+k):
    p1 = p[i]
    e1 = (1 + p1)*(p1//2 + 0.5*(p1%2))/p1
    e += e1

print(e)

Submission status: Time Limit Exceeded

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

def expectation(pp):
    return (pp * (pp + 1) / 2) / pp

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

result = 0

save_max = 0
save_idx = 0

for i in range(N - K + 1):
    s = sum(p[i : i + K])
    if s > save_max:
        save_idx = i
        save_max = s
    
print(sum([expectation(pp) for pp in p[save_idx : save_idx + K]]))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
p_list = list(map(int,input().split()))
ans_list = []
def E(me):
    if me == 1:
        return 1
    else:
        return ((1+me)*me/2)/me
E_list = [E(i) for i in p_list]
ans = 0
for i in range(N-K+1):
    ans = max(sum(E_list[i:i+K]),ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
P = list(map(lambda x:(int(x)+1)/2,input().split()))
S = []

for i in range(n-k+1):
    S.append(sum(P[i:i+k]))

print(max(S))

Submission status: Time Limit Exceeded

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

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

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

# print(ls_mu)

M = 0
for i in range(n-k+1):
    m = sum(ls_mu[i:i+k])
    M = max(m,M)

print(M)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split(' '))
    p_list = list(map(int, input().split(' ')))
    max_p_sum = 0
    sum_list = list()
    for n in range(0, N - K + 1, 1):
        if max_p_sum < sum(p_list[n: n + K]):
            max_p_sum = sum(p_list[n: n + K])
            sum_list = p_list[n: n + K]
    expected_value = [(1 + s) / 2 for s in sum_list]
    print(sum(expected_value))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

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

best=0
bestP=[0]*K
for i in range(N):
  if sum(P[i:i+K])>best:
    best=sum(P[i:i+K])
    bestP=P[i:i+K]
    

ans=0
for p in bestP:
  ans+=(p+1)/2
print(ans)

Submission status: Time Limit Exceeded

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

max_count = 0

for i in range(n-k+1):
    count = sum(p_list[i:i+k])
    max_count = max(max_count,count)

print(max_count/2 + k/2)

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
p_sum = [sum(p[i:i+k]) for i in range(len(p)-k+1)]
idx = p_sum.index(max(p_sum))
ans = 0
for p_i in p[idx:idx+k]:
    ans += ((p_i*(p_i+1))/2) / p_i
print(ans)

Submission status: Time Limit Exceeded

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

A = 0
for i in range(len(cnt)):
    A += (1+cnt[i])/2

print(A)

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
P = list(map(lambda x: (int(x) * (int(x) + 1)) / 2 / int(x), input().split()))
#print(P)
ans = 0
for i in range(N - K + 1):
  tmp = 0
  for j in range(i, i + K):
    tmp += P[j]
  if tmp > ans:
    ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    if type(s) != type('str'):
        s=str(s)

    sys.stderr.write(s+'\n')
    return

def expected_value(n):
    ans = 0

    for i in range(1, n+1):
        ans += i/n

    # eprint(ans)
    return ans

def main():
    n, k = map(int, input().split())
    Ps = list(map(int, input().split()))
    mi = -10**9
    ml = list()
    for i in range(n-k+1):
        if sum(Ps[i:i+k]) > mi:
            ml = Ps[i:i+k]
            mi = sum(Ps[i:i+k])
    
    v = int()
    for j in range(k):
        # 各サイコロについて期待値を求める
        v += expected_value(ml[j])

    
    print(v)
    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    ans = 0
    max_i = 0
    max_value = 0
    for i in range(N):
        t = 0
        for k in range(i, i+K):
            if len(p) > k:
                t += p[k]
            else:
                break
        if max_value < t:
            max_value = t
            max_i = i

    for i in range(max_i, max_i+K):
        if len(p) <= i:
            break
        n = p[i] + 1
        ans += (n*(n-1)//2) / (n-1)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

sum_ls=ls[:n]
rest_ls=ls[n:]
tmp=sum(sum_ls)
mx=tmp
for i in rest_ls:
    tmp=tmp-sum_ls[0]+i
    if tmp>mx:
        mx=tmp
    sum_ls.pop(0)
    sum_ls.append(i)

print((mx+n)/2)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
E=[0]*N
for i,p in enumerate(P):
  for j in range(p):
    E[i]+=(j+1)/p
ans=sum(E[:K])
_=sum(E[:K])
for i in range(1,N-K+1):
  _-=E[i-1]
  _+=E[i+K-1]
  if _>ans:
    ans=_
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

def main():
    keep_val = 0
    check = 0
    for i in range(n-k+1):
        ss = sum(p[i:i+k])
        if keep_val < ss:
            check = i
            keep_val = ss

    #print(p[check:check+k])

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

main()

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):
	semi = 0
	for j in range(P[i] + 1):
		semi += j
	ans += semi / P[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))
    res = 0
    for left in range(N - K + 1):
        right = left + K
        expected = sum([(x + 1) / 2 for x in ps[left:right]])
        if expected > res:
            res = expected
    print(res)

solve()

Submission status: Time Limit Exceeded

Solution code:
def calc_sum(i, p, k):
    r = 0
    for j in range(k):
        r = r + p[i + j]
    return r


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

    max_sum = 0
    for i in range(n - k + 1):
        # print(i, p, k)
        r = calc_sum(i, p, k)
        # print(r)
        if r > max_sum:
            max_sum = r

    print((max_sum / 2) + (k * 0.5))

Submission status: Time Limit Exceeded

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

sum_k = [0] * N
tmp = 0
for i in range(K):
    tmp += p[i]
sum_k[0] = tmp
max_sum = tmp
candidate = 0
for i in range(len(p)-K):
    sum_k[i+1] = sum_k[i] - p[i] + p[i+K]
    if max_sum < sum_k[i+1]:
        max_sum = sum_k[i+1]
        candidate = i+1


ans = 0
for i in range(candidate, candidate + K):
    tmp = 0
    for j in range(1, p[i]+1):
        tmp += j * (1 / p[i])
    ans += tmp
print(ans)

Submission status: Time Limit Exceeded

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

max_nums = 0
for idx in range(0, len(nums)-K+1):
    if sum(nums[idx:idx+K]) > max_nums:
        max_nums = sum(nums[idx:idx+K])
        max_list = nums[idx:idx+K]

kitai = 0

for num in max_list:
    sums = 0
    for i in range(1, num+1):
        sums += i
        
    kitai += sums/num

print(kitai)

Submission status: Time Limit Exceeded

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

# 期待値配列
E = [(p+1)/2 for p in P]

# 隣接K個を取り出して足す
max_E = 0
for i in range(N-K+1):
    tmp_E = sum(E[i: i+K])
    if tmp_E > max_E:
        max_E = tmp_E

print(max_E)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(n - k + 1):
    exv = 0
    for j in range(k):
        exv += (ls[i + j] + 1) / 2
    
    if exv > ans:
        ans = exv

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
P=[(int(x)+1)/2 for x in input().split()]
max=0
for i in range(N-K+1):
    kitai=0
    for k in range(K):
        kitai+=P[i+k]
    if max<kitai:
        max=kitai
print(max)

Submission status: Time Limit Exceeded

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

ma=0
for i in range(n-k+1):
       s=sum(P[i:i+k])
       if ma<s:
              ma=s
print((ma+k)/2)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = [int(_)*(int(_)+1)/(int(_)*2.0) for _ in input().split()]
max = 0

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

print(max)

Submission status: Time Limit Exceeded

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

ans_sect_total = 0

for i in range(len(nums) - k + 1):
    sum_nums_sect = sum(nums[i: i+k])
    if ans_sect_total < sum_nums_sect:
        ans_sect_total = sum_nums_sect

print((ans_sect_total + k) / 2)

Submission status: Time Limit Exceeded

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

tem=0
ans=0

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    if max_ps <= sum(ps[i:i+k]):
        start = i
        max_ps = sum(ps[i:i+k])

print(sum([sum(range(i+1))/i for i in ps[start:start+k]]))

Submission status: Time Limit Exceeded

Solution code:
def main(n,k,p):
    res = 0
    #期待値リスト
    kitai = [0]*n
    for i in range(len(p)):
        kitai[i] = (p[i]+1) / 2
    for i in range(k-1,len(p)):
        res = max(res, sum(kitai[i-k+1:i+1]))
    return res

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K+1):
    wa = 0
    for j in range(i,i+K):
        wa += Ex[j]
    maxi = max(maxi,wa)
print(maxi)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)

def main():
    n,k = map(int,input().split())
    p = list(map(int,input().split()))
    x = [0]
    _sum = 0
    for i in range(1,max(p)+1):
        _sum += i
        x.append(_sum)
    v = []
    for i in range(n):
        v.append(x[p[i]]/p[i])
    ans = 0
    for i in range(n-k+1):
        ans = max(ans,sum(v[i:i+k]))
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    r = 0
    for i in range(n-k+1):
        t = sum(P[i:i+k])
        r = r if r>t else t
    print((r+k)/2)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import 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 = MAP()
P = LIST()

acc = [0]*N
for i in range(N):
	su = 0
	for j in range(1, P[i] + 1):
		su += j/P[i]
	acc[i] = su

ma = 0
for i in range(N - K + 1):
	ma2 = 0
	for j in range(K):
		ma2 += acc[i+j]
	if ma < ma2:
		ma = ma2

print(ma)

Submission status: Time Limit Exceeded

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


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

    ep = [0] * N
    for i, x in enumerate(p):
        t = [x for x in range(1, x + 1)]
        e = sum(t) / x
        ep[i] = e

    tmp = sum(ep[:K])
    ans = tmp

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    ave_pl.append(p_sum/p)

ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(ave_pl[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()))
max_i = 0

for i in range(n-k+1):
    sum_i = 0
    for j in range(k):
        sum_i += p[i+j]
    
    if max_i < sum_i:
        max_i = sum_i

print((max_i+k)/2)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
e_p=[0]*n
for i in range(n):
    e_p[i]=(p[i]+1)/2
e_p_s=[]
for i in range(n-k+1):
    ep=0
    for j in range(k):
        ep+=e_p[i+j]
    e_p_s.append(ep)

print(max(e_p_s))

Submission status: Time Limit Exceeded

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

p = list(map(int, input().split()))
hope_list = []
max = 0
index = 0
for j in range(n-k+1):
    goukei = sum(p[j:j+k])
    if goukei > max:
        max = goukei
        index = j

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

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 = sum(range(1, p+1)) / 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()))

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

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
P = list(map(int,input().split()))
res = 0
def get_mean(q):
    enom = q * (1 + q) / 2
    num = q
    return enom / num
means = [get_mean(i) for i in P]
for i in range(N - K + 1):
    res = max(res,sum(means[i:i+K]))
print(res)

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)

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

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

Submission status: Time Limit Exceeded

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

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

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

ans = (ans+K)/2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    res = 0
    maxI = 0
    maxV = 0
    for i in range(N-K+1):
        v = sum(P[i:i+K])
        if v > maxV:
            maxV = v
            maxI = i
    for p in P[maxI:maxI+K]:
        res += (p+1.0) / 2.0
    print(res)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def resolve():
    input = sys.stdin.readline
    n,k = map(int,input().split())
    p = list(map(int,input().split()))
    s = []
    m = 0
    for i in range(n-k+1):
        if sum(p[i:i+k]) > m:
            s = p[i:i+k]
            m = sum(s)
    a = 0
    for i in range(k):
        a += (1+s[i])*s[i]/2/s[i]
    print(a)
resolve()

Submission status: Time Limit Exceeded

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

N, K = (int(nk) for nk in input().split())
P = [expected_value(int(p)) for p in input().split()]

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

print(max_ev)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,K = inputMap()
	P = inputList()

	kikan1 = 0
	maaxx = 0
	for i in range(N):
		if i+K > N:
			break
		tmp = 0
		for j in range(K):
			tmp += P[i+j]

		if tmp > maaxx:
			maaxx = tmp
			kikan1 = i

	ans = 0
	for j in range(K):
		tmp = P[kikan1+j]
		total = 0
		for jj in range(1,tmp+1):
			total += jj
		ans += total/tmp

	print(ans)

if __name__ == "__main__":
	main()