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 = list(map(int, input().split()))
p_list_copy = p_list.copy()

scope_index = -1
max_sum = 0
for p_i in range(len(p_list_copy)):
    now_sum = 0
    for i in range(k):
        if len(p_list_copy) < k:
            break
        now_sum += p_list_copy[i]

    if max_sum < now_sum:
        max_sum = now_sum
        scope_index = p_i
    p_list_copy.pop(0)

max_scope_list = []
for i in range(k):
    max_scope_list.append(p_list[scope_index + i])

ex = 0
for scope in max_scope_list:
    for num in range(1, scope+1):
        ex += num*1/scope
print(ex)

Submission status: Time Limit Exceeded

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

sum = 0
sum_p = 0
sum_l = []

for i in range(len(p) - K + 1):
    l = p[i:K]
    # print(l)
    for j in l:
        for k in range(j):
            k += 1
            sum += k / j
        # print(sum)
        sum_p += sum
        sum = 0
    sum_l.append(sum_p)
    sum_p = 0
    K += 1

print(max(sum_l))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
Num = list(map(int,input().split()))
MaxSumNum = 0
for i in range(0, N-K+1):
    res = int(sum(Num[i:i+K]))
    MaxSumNum = max(MaxSumNum, res)
print("%.12f"  % ((MaxSumNum + K)*0.5))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

kitai = list(map(lambda x: (x+1)/2, p))

gokei = []

for i in range(n-k+1):
    wa = sum(kitai[i:i+k])
    gokei.append(wa)

print(max(gokei))

Submission status: Time Limit Exceeded

Solution code:
def max_kitai_calc(n,k,data):
    temp = []
    for x in range(n-k+1):
        temp.append(sum(map(kitai,data[x:x+k])))

    return max(temp)

def kitai(p):
    return (1+p)/2

[n,k] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]

max_kitai = max_kitai_calc(n,k,data)

print(max_kitai)

Submission status: Time Limit Exceeded

Solution code:
def get_max_index(n, k, arr):
    tmp = 0
    index = 0
    tmp_arr = []
    for i in range(n - (k - 1)):
        sum_tmp = sum(arr[i:i+k])
        if sum_tmp >= tmp:
            tmp = sum_tmp
            index = i
            tmp_arr = arr[i:i+k]
    ans = 0
    for j in tmp_arr:
        tmp_sum = 0
        for m in range(1, j+1):
            tmp_sum += m
        ans += tmp_sum / j
    return ans

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

Submission status: Time Limit Exceeded

Solution code:
def kitai(x):
  k = 0
  for i in range(1,x+1):
      k += i/x
  return k

n, k = map(int, input().split())
p = list(map(int, input().split()))
ki_l = []
ans_l = []
for i in p:
  ki_l.append(kitai(i))
for i in range(n - k + 1):
  ans_l.append(sum(ki_l[i:i+k]))
print(max(ans_l))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
edge = 0
maximum = 0
result = 0
for i in range(n-k+1):
        summ = sum(p[i:i+k])
        if summ > maximum:
                edge = i
                maximum = summ
for i in range(k):
        result += sum(range(p[edge+i]+1))/p[edge+i]
print(result)

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 = []
sum_ans = 0
for i in range(k):
    sum_ans += kitai[i]
ans.append(sum_ans)
j = 0
cnt = 0
for i in range(k,len(kitai)):
    sum_ans = ans[cnt]
    d = kitai[i] - kitai[j]
    sum_ans += d
    j +=1
    cnt+=1
    ans.append(sum_ans)
ans = sorted(ans)
print(ans[-1])

Submission status: Time Limit Exceeded

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

dice = list(map(int, input().split()))
a = 0
b = 0
for j in range(k):
    a += dice[j]
    b += dice[j]
res = 0
ll = 0
s = 0
for i in range(len(dice)):
    if i < k:
        continue
    a += dice[i]
    a -= dice[s]
    if a > b:
        b = a
        ll = i
    s += 1

for mn in range(ll - k + 1, ll + 1):
    ss = range(dice[mn] + 1)
    res += sum(ss) / dice[mn]
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

m = p[0:K]
for i in range(1,N-K+1):
    if sum(m) < sum(p[i:K+i]):
        m = p[i:K+i]
e = np.array(m)
a = e/2
n = sum(a) + 0.5 * K
print(n)

Submission status: Time Limit Exceeded

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

sum_p = []

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

ex = (max(sum_p)-K+2)/2

print(ex + K - 1)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

number = input().split(" ")
N = int(number[0])
K = int(number[1])
p_list = input().split(" ")
new = []
for i in p_list:
    value = 0
    for j in range(int(i)+1):
        value += j
    value = value/int(i)
    new.append(value)
ans = []
for i in range(len(new)):
    if i+K <= len(new):
        answer = 0
        for i in range(i,i+K):
            answer += new[i]
        ans.append(answer)
    else:
        pass
ans.sort()
print(ans[-1])

Submission status: Time Limit Exceeded

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

max = 0
for i in (range(n-k+1)):
    sum_k = sum(p[i:i+k])
    newI = (sum_k + k)/2.0
    if(max < newI):
        max = newI

print(max)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
L=list(map(int,input().split()))
M=0
M_IND=0

for i in range(len(L)-(K-1)):
  tmp = sum(L[i:i+K])
  #print(tmp)
  if M < tmp:
    M = tmp
    M_IND=i
#print(M_IND)
#for k in range(L[M_IND,M_IND+K])
ANS=0
MEMO=[0]*(max(L[M_IND:M_IND+K])+1)
MEMO_MIN=0
for i in L[M_IND:M_IND+K]:
  #print(i)
  ex = 0
  p = 1/i
  if MEMO[i] == 0:
    for x in range(i+1):
        px = p*x
        ex += px
    MEMO[i] = ex
  else:
    ex = MEMO[i]
  ANS += ex
print(ANS)

Submission status: Time Limit Exceeded

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

l = []
m = []

s = 0

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

for i in range(n - k + 1):
    for j in range(k):
        s += l[j + i]
    m.append(s)
    s = 0

print(max(m))

Submission status: Time Limit Exceeded

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

max = 0
for i in range(len(p_n)-(k-1)):
    tmp = p_n[i]
    for j in range(k-1):
        tmp = tmp + p_n[i+j+1]
    if tmp > max:
        max = tmp


print((max+k)*0.5)

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

ans_lis = np.array([i for i in p])
for i in range(1,K):
  ans_lis = ans_lis[:-1] + p[i:]

#anss = [0 for i in range(N-K+1)]
#for i in range(0, N-K+1):
#  anss[i] = sum(p[i:i+K])
  #ans = sum(p[i:i+K])
  #if ans > max_ans:
  #  max_ans = ans
    
print((max(ans_lis)+K)/2)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
List = list(map(int, input().split()))
score = []
max = 0
index = 0
res = 0

a = n - k + 1
b = k - 1

for i in range(a):
    pre = List[i]
    for j in range(b):
        pre += List[i+j]
    #print(max)

    if max < pre:
        max = pre
        index = i
        pre = 0
    else:
        pre = 0
    
#print(index)
for i in range(index, index+k):
    res += 1 + 0.5 * (List[i]-1)
    #print(List[i])

print(res)

Submission status: Time Limit Exceeded

Solution code:
def kitai(num):
    #k = 0
    #for ni in range(1, num + 1):
    #    k += ni / num
    return num / 2 + 0.5

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

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

nums = p[ind: ind+k]

r = 0
for num in nums:
    r += kitai(num)

print(r)

Submission status: Time Limit Exceeded

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


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

# main
N, K = mis()
p = lmis()

exs = [0] * N

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

if N == K:
    print(sum(exs))
    exit(0)

ex_max = 0
for i in range(N-K+1):
    ex_temp = 0
    for j in range(i, i+K):
        ex_temp += exs[j]

    if ex_max < ex_temp:
        ex_max = ex_temp

print(ex_max)

Submission status: Time Limit Exceeded

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

def kitai(x):
  p = 1/x
  ex = 0
  for i in range(1, x+1):
    px = p*i
    ex += px
  return ex

mem = {}
isum = 0
keys = (0, 0)
for i in range(n):
  if i+k > n:
    break
  temp = p[i:i+k]
  if sum(temp) > isum:
    isum = sum(temp)
    keys = (i, i+k)

print(kitai(isum+(k-1)))

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())))
q = 1 + 0.5 * (p - 1)
X = []

for i in range(N):
    if i + K > N:
        break
    else:
        X.append(sum(q[i:i+K]))

print(max(X))

Submission status: Time Limit Exceeded

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

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


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

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

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

print(max)

Submission status: Time Limit Exceeded

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

max = -1
ans=0


for i in range(0,n-k+2):
    buf = p[i:i+k]
    tmp = sum(buf)
    if tmp > max:
        max = tmp
        li = p[i:i+k]

for j in range(len(li)):
    s_buf = 0
    for l in range(1,li[j]+1):
        s_buf+=l
    ans += s_buf/li[j]
    s_buf=0

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 (n + 1) / 2


len_sum = -1
max_len = None
for i in range(N):
    if len(P[i:i + K]) == K:
        l = sum(P[i:i + K])
        if l > len_sum:
            max_len = P[i:i + K]
            len_sum = sum(max_len)

print(sum(map(calc_exp, max_len)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k= map(int, input().split())
p = list(map(int,input().split()))
a = np.zeros(n, dtype = float)
for i in range(0,n):
	a[i] = (p[i]+1)/2
s = 0
for i in range(0,n-k+1):
	l = 0
	for j in range(i,k+i):
		l += a[j]
	if l > s:
		s = l
print(s)

Submission status: Time Limit Exceeded

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

arr = []
tmp = 0

for n in P:
  arr.append((n*(n+1)/2)/n)

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

print("{:.12f}".format(tmp))

Submission status: Time Limit Exceeded

Solution code:
def main():
  a,b=map(int,input().split())
  List=list(map(int, input().split()))
  sum=0
  maxsum=0
  for i in range(len(List)-b+1):
    for j in range(b):
      sum = sum + List[i+j]
    sum = (sum+b)/2
    #sum = (List[i]+List[i+1]+List[i+2]+b)/2
    if maxsum < sum:
      maxsum=sum
    sum=0
  print(maxsum)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

a = []
#print(a)
ans = -1
ruiseki = []
for i in range(n-k+1):
    ruiseki.append(sum(p[i:i+k]))
print(max(ruiseki))

Submission status: Time Limit Exceeded

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

saikoro = [0] * 1001
for i in range(1, 1001):
    saikoro[i] = (saikoro[i-1] + i)


 
 
ans = 0
for j in range(n - k + 1):
    sums = 0
    for z in range(j,j + k):
        sums += saikoro[p[z]] / p[z]
    ans = max(ans, sums)
 
print(ans)

Submission status: Time Limit Exceeded

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

m = sum(pn[0:k])
for i in range(k, n):
    if pn[i-k] > pn[i]:
        continue
    else:
        mi = sum(pn[i-k+1:i+1])
        if m < mi:
            m = mi
print((m + k)/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if len(p) == K:
    kitaiti = 0
    for i in range(len(p)):
        # 一個の数字
        sum = 0
        for j in range(p[i] + 1):
            sum += j
        kitaiti += sum / p[i]
    print(kitaiti)
else:
    max = 0
    max_index = 0
    # 期待値計算に使うリスト 最大のKつ並び
    l = []
    # 最大のKつ並びを見つける
    # iは始点(0スタート)
    # K + i は終点
    for i in range(len(p) - K + 1):
        tmp = sum(p[i:K + i])
        # もしmaxの次だったら、sumの計算が要らない
        # 共通部品以外を比較する
        if i != 0 and i == max_index + 1:
            if l[0] < p[K + i - 1]:
                max = tmp
                max_index = i
                l = p[i:K + i].copy()    
        elif tmp > max:
            max = tmp
            max_index = i
            l = p[i:K + i].copy()
    
    # 期待値の計算
    kitaiti = 0
    for i in range(len(l)):
        # 一個の数字
        sum = 0
        for j in range(l[i] + 1):
            sum += j
        kitaiti += sum / l[i]
    print(kitaiti)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
A=[0]
if K!=1:
  for k in range(0,N-K+1):
    On=0
    for l in range(0,K):
      On+=P[k+l]
    A.append(On)
  print((max(A)+K)/2)
elif K==N:
  print((sum(P)+N)/2)
else:
  print((max(P)+1)/2)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
p = tuple(map(int, sys.stdin.readline().split()))

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

#E = [None]*K
E = [sum(range(1, p[index+i]+1))/p[index+i] for i in range(K)]
"""
for i in range(K):
    E[i] = sum(range(1, p[index+i]+1))/p[index+i]
"""
print(sum(E))

Submission status: Time Limit Exceeded

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

l=[]
m=0
po=0

for i in range(len(p)-k+1):  
    s=0
    for j in range(k):
        s+=p[i+j]
    if(s > m):
        m = s
        po = i

sp = []

for j in range(k):
    sp.append(p[po+j])

exp=[]
for i in sp:
    exp.append((i+1)/2)
        
print(float(sum(exp)))

Submission status: Time Limit Exceeded

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



def main():
    N,K=map(int,input().split())
    mytuple= tuple(map(int, input().split()))
    tempmax=0
    temptuple=()
    answer=0

    for i in range(N-K+1):
        temptuple=mytuple[i:i+K]
        #print(temptuple)
        tempmax=sum(temptuple)
    
        if  answer<tempmax:
            answer=tempmax
        
    print((answer+K)/2)

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def cal_ans(x):
    ans = (x*(x+1)/2)/x
    return ans
n,k = map(int,input().split())
p = list(map(int,input().split()))
p =  list(map(cal_ans,p))

ans_temp = 0
ans_list = []
for i in range(n):
    try:
        if ans_temp < sum(p[i:i+k]):
            ans_temp = sum(p[i:i+k])
            ans_list = p[i:i+k]
    except:
        pass
print(ans_temp)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque


def calc_expectation(dice):
    return sum(list(range(1, dice + 1))) / dice


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
p = [int(c) for c in line]

max_E = 0
expectations = deque(maxlen=K)
for _ in range(K):
    expectations.append(0)

for s_idx in range(0, N):
    expectations.popleft()
    dice = p[s_idx]
    e = calc_expectation(dice)
    expectations.append(e)
    E = sum(expectations)
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)

Submission status: Time Limit Exceeded

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

ans = 0

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def dice_eq(x):
    eq=0
    for i in range(x):
        eq+=(i+1)/x
    return eq
equit=0
N,K=map(int,input().split())
data=list(map(int,input().split()))
#print(data)
ansb=[]
for j in range(N):
    equit=dice_eq(data[j])
    ansb.append(equit)
kt=0
for n in range(K):
    kt+=ansb[n]
kt_check=kt
for m in range(N-K+1):
    kt=0
    for n in range(K):
        kt+=ansb[m+n]
    if kt >= kt_check:
        kt_check=kt
print(kt_check)

Submission status: Time Limit Exceeded

Solution code:
x=0
y=0
N,K=map(int,input().split())
P=list(map(int,input().split()))
i=1
while i+K<N+1:
  if sum(P[i:i+K])>x:
    x=sum(P[i:i+K])
    y=i
  i=i+1

S=0
for i in range(y,y+K):
  S=S+(1+P[i])/2

print("{0:.12f}".format(S))

Submission status: Time Limit Exceeded

Solution code:
firstLine = input().split()
secondLine = input().split()
pList = []
N = int((firstLine[0]))
K = int(firstLine[1])

kitaichiList = []
countingList = []
sumList = []


for n in range(N):
    pList.append(int(secondLine[n]))

tryTimes = N - K + 1

for n in range(len(pList)):
    counted = 0.0
    countingList = []
    for caling in range (pList[n]):
        countingList.append(float((1/pList[n]) * (caling+1)))
    for a in range(len(countingList)):
        counted = counted + countingList[a]
    kitaichiList.append(float(counted))

startIndex = 0

for startIndex in range(tryTimes):
    sumCount = 0.0
    for a in range(K):
        sumCount = sumCount + kitaichiList[startIndex+a]
    sumList.append(float(sumCount))

print(max(sumList))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(final_ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(n) for n in input().split()]
P =  [int(n) for n in input().split()]
o = {}
for i in range(1,1001):
    o[i] = sum([(j/i) for j in range(1,i+1)])
ans = 0
for k in range(N-K+1):
    m = sum([o[x] for x in P[k:k+K]])
    if m > ans:
        ans = m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(str, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    S, T= LS()
    A,B= LI()
    U= input().rstrip()



    if(S==U):
        print(A-1,B)
    else:
        print(A,B-1)


    
    return

# B


def B():
    A=input().rstrip()
    ans='x'
    for i in range(len(A)-1):
        ans+='x'
    print(ans)
        
    


    return

# C


def true():
    S = input()
    S = S[:-1]

    tmp = 0
    for x in range(1 << (len(S)-1)):
        func = S[-1]
        for i in range(len(S)-1):
            if(x & (1 << i)):
                tmp += int(func)
                func = S[-2-i]
            else:
                func = S[-2-i]+func
        tmp += int(func)
    print(tmp)

    return


def C():
    N = II()
    A=LI()
    AA=set(A)
    if (len(A)==len(AA)):
        print('YES')
    else:
        print('NO')
    return

        


        

# D


def D():

    N,K=LI()
    P=LI()
    tmp=sum(P[:K])
    s=0
    pp=sorted(P, reverse=True)
    tmpmax=sum(pp[:K])
    for i in range(K,N+1):
        if (P[i-1]>P[s-1] and s!=0):
            tmp2=sum(P[s:i])
            if (tmp2==tmpmax):
                tmp=tmp2
                break
            tmp=max(tmp,tmp2)
        s+=1
        

    print((tmp+K)/2)
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':

    D()

Submission status: Time Limit Exceeded

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

def kitaiti(n , k , p):

    ans = 0
    count = 0
    kitai = [0]*n
    mod = 10**9+7

    for i in range(n):
        kitai[i] = round(tasu(p[i]) / p[i] , 6)

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

        count = sum(kitai[i:i+k]) % mod
 #       for w in range(i , i + k):
#            count += kitai[w]
#            count += tasu(p[w]) / p[w]
        ans = max(ans , count)

    return ans

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

if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

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

  def CalExVal(x):
      return (1/2*(x+1))
  Ex = list(map(CalExVal, A))
  temp = len(A)-K + 1
  #adjlist = [0]*(temp)
  adjlist = [sum(Ex[i:(K+i)]) for i in range(temp)]
  #for i in range(temp):
  #    adjlist[i] = sum(Ex[i:(K+i)])

  print(max(adjlist))
main()

Submission status: Time Limit Exceeded

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

print((1/2)*(max([sum(Pi[i:i+K]) for i in range(N-K+1)]) + K))

Submission status: Time Limit Exceeded

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

aaa = 0
list_ans = []
i = 0
while i < n-k+1:
    a = sum(list[i:i+k])
    if aaa <= a:
        aaa = a
        list_ans = list[i:i+k]
    i += 1 

ans = 0
i = 0
while i < len(list_ans):
    ans += (list_ans[i]+1)/2
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

ans_lis = [i for i in p]
for i in range(1,K):
  ans_lis = [ans_lis[k]+j for k,j in enumerate(p[i:])]

#anss = [0 for i in range(N-K+1)]
#for i in range(0, N-K+1):
#  anss[i] = sum(p[i:i+K])
  #ans = sum(p[i:i+K])
  #if ans > max_ans:
  #  max_ans = ans
    
print((max(ans_lis)+K)/2)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
l = list(map(int,input().split()))
 
def E(n):
  return sum(range(1,n+1)) / n
 
j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
elif N == K:
  l2 = list(map(E, l))  
  print(sum(l2))
else:
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]

  l2 = list(map(E, t))
 
  print(sum(l2))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

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

ans = 0
for i in range(len(A)):
    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()))

ls = P[0:K]
summ = sum(ls)
ans = [0]*K

for i in range(N-K+1):
    if summ < sum(P[i:i+K]):
        ls = P[i:i+K]
        summ = sum(ls)
for j in range(K):
    ans[j]=(ls[j]+1)*ls[j]/(2*ls[j])
print(sum(ans))

Submission status: Time Limit Exceeded

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

sum = 0
sumList =[]

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
a = [int(b) for b in input().split()]
l = input().split()
l = np.array([int(n) for n in l])
b = a[0] - a[1]+1


maximum = 0
n = [l[i:i+a[1]].sum() for i in range(b)]

print(0.5*(max(n)+a[1]))

Submission status: Time Limit Exceeded

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

dice = list(map(int, input().split()))
a = 0
b = 0
for j in range(k):
    a += dice[j]
    b += dice[j]
res = 0
ll = 0
s = 0
for i in range(len(dice)):
    if i < k:
        continue
    a += dice[i]
    a -= dice[s]
    if a > b:
        b = a
        ll = i
    s += 1

for mn in range(ll - k + 1, ll + 1):
    ss = range(dice[mn] + 1)
    p = 1 / dice[mn]
    ex = 0
    for x in ss:
        px = p * x
        ex += px
    res += ex
print(res)