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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
ls.append([ans,0])

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    ls.append([ans,i+1])
    

ls = sorted(ls,reverse=True)

ans = 0
for i in range(k):
    for j in range(p[ls[0][1]+i]):
        ans += (1/p[ls[0][1]+i]*(j+1))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
pi = list(map(int, input().split()))
K_sum = []
for i in range(N-K+1):
    K_sum.append(sum(pi[i:i+K])) 
index = K_sum.index(max(K_sum))

def Expected_Value(x):
    EV = 0
    for i in range(1,x+1):
        EV += i/x
    return EV

EV_Dice = 0
for i in range(index,index+K):
    EV_Dice += Expected_Value(pi[i])
print(EV_Dice)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

def expect(pi):
    sum = 0.0
    for i in range(1, pi+1):
        sum += float(i)
    return sum/float(pi)

def solve1(N: int, K: int, p: "List[int]"):

    ans = 0.0
    for n in range(N-K+1):
        sum_exp = 0.0
        for e in range(K):
            sum_exp += expect(p[n+e])
        if ans < sum_exp:
            ans = sum_exp
    print(ans)

    return

def solve(N: int, K: int, p: "List[int]"):

    max_int = 0
    max_idx = 0
    for n in range(N-K+1):
        sum_int = 0
        for e in range(K):
            sum_int += p[n+e]
        if max_int < sum_int:
            max_int = sum_int
            max_idx = n

    sum_exp = 0.0
    for e in range(K):
        sum_exp += expect(p[max_idx+e])
    print(sum_exp)

    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def sum(n):
	s = 0
	y = 1
	while y <= n:
		s += y
		y += 1
	return s

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

m = 0

for i in range(N-K+1):
	ans = 0
	for j in range(i, i+K):
		ans += sum(x[j]) / x[j]

	if ans > m:
		m = ans

print(m)

Submission status: Time Limit Exceeded

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

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

ans = 0
for j in range(max_index, max_index+k):
  su = 0
  for l in range(1, p[j]+1):
    su += l
  ans += su / p[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):
  exp = sum(p[i:i+K])
  if exp >= ans:
    ans = exp

    
print((ans+K)/2)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
e = [sum(range(1, pi + 1)) / pi for pi in p]

tmp = 0
for i in range(n):
    tmp += e[i]
    if i >= k:
        tmp -= e[i - k]
    ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

box = [P]
for i in range(1,K):
    box.append(P[i:]+[0]*i)

large = np.sum(np.array(box),axis=0)
ind = np.argmax(large)

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

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

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

Submission status: Time Limit Exceeded

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

max_sum = 0
for i in range(N-K+1):
    tmp_sum = sum(P[i:i+K])
    if tmp_sum > max_sum:
        max_sum = tmp_sum

max_E = (max_sum + K) / 2
print(max_E)

Submission status: Time Limit Exceeded

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

cnt=0
ans=0
q=deque([])
for i in range(N):
    q.append(P[i]*(P[i]+1)//2/P[i])
    if len(q)==K:
        if sum(q)>ans:
            ans=sum(q)
        q.popleft()
print(ans)

Submission status: Time Limit Exceeded

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

ansi = 0
maxtem = 0
for i in range(n - k + 1):
  tem = sum(p[i:i+k])
  if tem > maxtem:
    ansi = i
    maxtem = tem

ans = 0
for j in range(ansi ,ansi + k ):
  ans += (p[j] + 1 ) / 2

print(ans)

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


def culc_exp(n):
    return 0.5 * (n+1)

p_n = list(map(lambda x:culc_exp(x),p_n))

def sum_list_a_to_k(list,a,k):
    result = 0
    for i in range(k):
        result = result+list[a+i]
    return result





def max_tuple(list):
    max = 0
    for i in range(len(list)-(k-1)):
        tmp = sum_list_a_to_k(list,i,k)
        if tmp > max:
            max = tmp
    return max


print(max_tuple(p_n))

Submission status: Time Limit Exceeded

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

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 permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
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 LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()

    ans = 0
    tmp = 0

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

    #print(li)

    for x in li:
        ans += sum(range(1,x+1))/x

    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()))
ans = []
kitaiti = 0
for i in range(len(p)):
    ans.append(sum(p[i:i+k]))
key = ans.index(max(ans))
ans_list = p[key:key+k]
for i in ans_list:
    kitaiti += (((1+i)/2)*i)*i**-1
print(kitaiti)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc154/tasks/abc154_d
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
p = [int(i) for i in input().split()]
E = []
A = []
for k in range(N):
  E.append(0)
  for i in range(1,p[k]+1):
    E[k] = E[k]+i/p[k]
for i in range(N-K+1):
  kitai = 0
  for k in range(K):
    kitai = kitai + E[k+i]
  A.append(kitai)
print(max(A))

Submission status: Time Limit Exceeded

Solution code:
def kita(N):
    a = 0
    for i in range(1, N + 1):
        a += i
    return a / N


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

l = []
for i in p:
    l.append(kita(i))

#print(l)

a = []
for i in range(n):
    len_s = len(l[i:i + k])
    if len_s < k:
        break
    else:
        a.append(sum(l[i:i + k]))

print(max(a))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def sum_to(n):
    return (n+1)*int((n/2))+(n%2)*((n+1)/2)

def expected(n):
    return sum_to(n) / n

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

max_sum = 0
select = deque()
c = 0
for i in P:
    e_val = expected(i)
    select.append(e_val)
    if len(select) == K:
        s = sum(select)
        if s > max_sum:
            max_sum = s
        select.popleft()

print(max_sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def K(n):
    return 0.5 * (n + 1)

def d():
    n, k = input().split()
    n = int(n)
    k = int(k)
    p = input().split()

    m = 0
    for i in range(0, len(p)-k+1):
        a = 0
        for i2 in range(k):
            a += int(p[i+i2])
        if m < a:
            m = a
            I = i
    m2 = 0
    for i in range(k):
        m2 += K(int(p[I + i]))
    return m2
print(d())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
###########　入力
# 整数の入力
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

maxSum = 0  #最大出目の合計値　の最大値
maxSumPoint = 0
maxExp = 0

for i in range(0, N-K+1):
    exp = 0
    for j in range(K):
        exp += p[i+j]
    if exp > maxSum:
        maxSum = exp
        maxSumPoint = i

for i in range(maxSumPoint, maxSumPoint+K):
    maxExp += (p[i]+1)/2    #個別の期待値
###########　出力
print(maxExp)

Submission status: Time Limit Exceeded

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

l = [(1 + p1)*(p1//2 + 0.5*(p1%2))/p1 for p1 in p[idx:idx+k]]

print(sum(l))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import numpy

def main():
  n, k = map(int, input().strip().split())
  Ps   = numpy.array(input().strip().split(), dtype=int)
  Es   = numpy.zeros(n)
  max = -1
  for i, P in enumerate(Ps):
    Es[i] = 0.5 * (P+1)
  max = -1
  for i in range(n-k+1):
    x = numpy.sum(Es[i:i+k])
    if max < x:
      max = x
  print(max)

if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

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

max_val = 0
for i in range(0, len(p)-k+1):
  tmp = p[i:i+k]
  val = sum([sum([x for x in range(1, t+1)]) / t for t in tmp])
  
  if max_val < val:
    max_val = val

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

Submission status: Time Limit Exceeded

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



def calc(x):
    sum_p = 0
    for i in range(x,x+K):
        sum_p = sum_p + p[i]
        #print(sum_p)
    return sum_p

def max_cal(max_p,sum_p):
    if(max_p < sum_p):
        max_p = sum_p
    return max_p

if __name__ == '__main__':
    max_p = 0
    for j in range(N-K+1):
        sum_p = calc(j)
        max_p = max_cal(max_p, sum_p)
    #print(max_p)
    print((max_p+K)/2)

Submission status: Time Limit Exceeded

Solution code:
def calc(A):
    res = 0
    res = (1+A)/2
    return res
    
N, K = map(int, input().split())
P = list(map(int, input().split()))
res = 0
ind = 0
for i in range(N-K+1):
    part = 0
    part = sum(P[i:i+K])
    if res < part:
        res = part
        ind = i
ans = 0
for i in range(K):
    ans += calc(P[ind+i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 154: D (2020/02/09)
import math
N, K = map(int, input().split())
l = input().split()
p = [0 for i in range(N)]
for i in range(N):
    p[i] = sum([i for i in range(1, int(l[i])+1)])/int(l[i])
max_sum = 0
for i in range(N-K+1):
    sum1 = 0
    for j in range(i,i+K):
        sum1 = sum1 + p[j]
    if max_sum < sum1:
        max_sum = sum1
print(max_sum)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = []
for i in range(len(p)-k+1):
  c.append(sum(p[i:i+k]))
#print(c)
#pn = np.array(p)
#v = np.array([1]*k)
#c = np.convolve(pn, v, mode='same')
print((max(c)+k)/2)

Submission status: Time Limit Exceeded

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

prev = 0
ind = 0
for i in range(n - k + 1):
    nex = 0
    for j in range(i, i + k):
        nex += p[j]

    if prev < nex:
        prev = nex
        ind = i

total = 0
for i in range(ind, ind + k):
    total += (1 + p[i]) * (p[i] / 2) / p[i]

print(total)

Submission status: Time Limit Exceeded

Solution code:
def main(n, k, p: list):
    ans = 0

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

        for j in p[i : i + k]:
            for _k in range(1, j + 1):
                t += _k * (1 / j)

        ans = max(ans, t)

    print("{:06f}".format(ans))


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

    main(n, k, p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

max_scope_list = []
for p_i in range(len(p_list)):

    now_scope_list = []
    for i in range(k):
        if len(p_list) <= (p_i + i):
            break
        now_scope_list.append(p_list[p_i + i])

    if sum(max_scope_list) < sum(now_scope_list):
        max_scope_list = now_scope_list

ex = 0
for scope in max_scope_list:
    dice = [r for r in range(1, scope+1)]
    p = 1/len(dice)
    for d in dice:
        ex += p*d
print(ex)

Submission status: Time Limit Exceeded

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

dic = {}

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

Submission status: Time Limit Exceeded

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

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

maxval = 0


def expectedval(inp):
	return (1 + inp) /2

maxcomb = []
maxsum = 0
bestpos = 0

for i in range(n-(k-1)):
	summ = 0
	for j in range (k):
		summ += plist[i + j]
	if summ > maxsum:
		maxsum = summ
		bestpos = i

res = 0
for j in range (k):
	res += expectedval(plist[bestpos + j])

print(res)

Submission status: Time Limit Exceeded

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


t = [0]*(n-k+1)
tmp = 0
for i in range(n-k+1):
    for x in range(k):
        num = p[i+x]
        tmp += sum(range(num+1)) / num
    t[i] = tmp
    tmp = 0

print(max(t))

Submission status: Time Limit Exceeded

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

loop_time = N - K + 1

l_s = 0
l_e = K
max_score = 0
for i in range(loop_time):
    test_list = p_list[l_s:l_e]
    test_e = 0
    for j in test_list:
        e = sum(range(1,j+1)) / j
        test_e = test_e + e
    if test_e > max_score:
        max_score = test_e
    l_s = l_s + 1
    l_e = l_e + 1

print(max_score)

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
    # 期待値計算に使うリスト 最大のKつ並び
    l = []
    # 最大のKつ並びを見つける
    # iは始点(0スタート)
    # K + i は終点
    for i in range(len(p) - K + 1):
        tmp = sum(p[i:K + i])
        if tmp > max:
            max = tmp
            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:
def calcExValue(N):
    ev = []
    for i in range(1, N +1):
        ev.append(i * (1/N))
    return(sum(ev))

def sumEvs(numbers):
    evs = []
    for N in numbers:
        evs.append(calcExValue(N))
    return(sum(evs))

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

max_numbers = []
max_exv = 0
for i in range(N-K+1):
    exv = sumEvs(array[i:i+K])
    if exv > max_exv:
        max_exv = exv
 
print(max_exv)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
edge = 0
maximum = 0
for i in range(n-k+1):
        if sum(p[i:i+k]) > maximum:
                edge = i
                maximum = sum(p[i:i+k])
result = 0
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 = list(map(int, input().split()))
p_list = list(map(int, input().split()))

number_list = []

sum_max = 0
for index, p in enumerate(p_list):
    number_list.append((p * (p + 1)) / 2 / p)
    if index >= K - 1:
        sum_total = sum(number_list[index-(K - 1):index + 1])
        if sum_max < sum_total:
            sum_max = sum_total

print('{:.12f}'.format(float(sum_max)))

Submission status: Time Limit Exceeded

Solution code:
import numpy
N, K = map(int, input().split())
p = numpy.array(list(map(int, input().split())))
max = 0
for i in range(N-K+1):
    temp = numpy.sum(p[i:i+K])
    if max < temp:
        max = temp
        maxno = i

exsum = 0

for i in range(K):
    dice = numpy.arange(1, p[i+maxno]+1)
    numpy.sum(dice)/len(dice)
    exsum += numpy.sum(dice)/len(dice)
print(exsum)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
pn = list(map(int, input().split()))
 
maxlist = 0
for i in range(N-K+1):
    p = pn[i:i+K]
    maxlist = max(maxlist, sum(p))
 
ans = (maxlist+K)/2
print('{:.12f}'.format(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def get_expect(p):
    return 1.0 * (p + 1) / 2

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = np.frompyfunc(get_expect, 1, 1)(P)

    print(max([
        np.sum(
            e[i:i + K]
        )
        for i in range(N - K + 1)
    ]))

if __name__ == "__main__":
    main()

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(j for j in range(1,p[i]+1))/p[i])
for i in range(n-k+1):
    r.append(sum(q[j] for j in range(i,i+k)))
r.sort(reverse=True)
print(r[0])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, k, *p = map(int, open(0).read().split())

max_r = 0
max_i = 0
for i in range(n-k+1):
  r = sum(p[i:i+k])
  
  if r > max_r:
    max_r = r
    max_i = i
    
max_e = 0
for j in range(max_i, max_i+k):
  max_e += (p[j]+1)/2

print(max_e)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
ilist = list(map(int,input().split()))
max_dice = 0
ind = 0
for i in range(0, N-K+1):
    s = sum(ilist[i:i+K])
    if s > max_dice:
        max_dice = s
        ind = i
max_p = (sum(ilist[ind:ind+K])+K)/2
print(max_p)

Submission status: Time Limit Exceeded

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

max = 0
for n in range(N):
  l = n
  r = n
  sum = 0.5 * (p_list[n]+1)
  len = 1
  while(len < K):
    if(l == 0):
      r += 1
      sum += 0.5 * (p_list[r]+1)
      len += 1
      continue
    if(r == N - 1):
      l += -1
      sum += 0.5 * (p_list[l]+1)
      len += 1
      continue
    if(p_list[l-1] >= p_list[r+1]):
      l += -1
      sum += 0.5 * (p_list[l]+1)
      len += 1
    else:
      r += 1
      sum += 0.5 * (p_list[r]+1)
      len += 1
  if(sum > max):
        max = sum
print(max)

Submission status: Time Limit Exceeded

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

ini = 0
L = []
for i in range(N-K+1):
    l = P[i:i+K]
    m = sum(l)
    if m > ini:
        ini = m
        L = l
s = [1+(i-1)*0.5 for i in L]
print(sum(s))

Submission status: Time Limit Exceeded

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

pmax=0
for i in range(n-k+1):
    psum=sum(pi[i:i+k])
    if psum>pmax:
        pmax=psum
px=(k+pmax)/2
print(px)

Submission status: Time Limit Exceeded

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

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

    for i in range(len(l)-(k-1)):
        s = sum(l[i:i+k])

        if out < s:
            out = s
            out_i = i

    r = sum(map(mean, l[out_i:out_i+k]))
    print(r)

def mean(x):
    x = x
    return x * (x+1) / (2 * x)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

R=[]
for i in range(len(P)-K+1):
  R.append(sum(P[i:i+K]))
m=max(R) 
l=(m+K)/2
print(l)

Submission status: Time Limit Exceeded

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

arr = [0] * (N)
tmp = 0

for i in range(N):
  n = P[i]
  arr[i] = (n*(n+1)/2)/n

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

print(tmp)

Submission status: Time Limit Exceeded

Solution code:
input_line = [int(i) for i in input().split(" ")]
k = input_line[1]

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

excepted_value = []
for i in input_line:
    excepted_value.append((i+1) / 2)

max_excepted_value = 0
for i in range(len(input_line) - k + 1):
    sum_excepted_value = sum(excepted_value[i: i+ k])
    if max_excepted_value < sum_excepted_value:
        max_excepted_value = sum_excepted_value
print(max_excepted_value)

Submission status: Time Limit Exceeded

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

exp_val = [n/2+0.5 for n in p]
ksum = []
for i in range(N-K+1):
    ksum.append(sum(exp_val[i:i+K]))
print(max(ksum))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

sum_num = N - (K - 1)
pick_que = deque(p_list[0:K])
sum_list = [int(sum(pick_que))]

for i in range(sum_num):
    if i == 0:
        continue
    else:
        pick_que.append(p_list[K + i - 1])
        pick_que.popleft()
        tmp_sum = sum(pick_que)
        sum_list.append(int(tmp_sum))

max_p = max(sum_list)

print(max_p/2 + 0.5 * K)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int, input().split())
l = list(map(int, input().split()))
max = 0
e = 0
temp = 0
pr = []
ll = []

for x in l:
  pr += [(x+1)/2]

for i in range(a-b+1):
  ll += [sum(pr[i:i+b])]
ll.sort()
print(ll[-1])

Submission status: Time Limit Exceeded

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

pnmax = 0
for i in range(0, n-k+1):
  pn = 0
  for j in range(k):
  	pn = pn + ps[i+j]
  pnmax = max(pnmax, pn)

print((pnmax+k)/2)

Submission status: Time Limit Exceeded

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

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

p = list(map(int,input().split()))
counter_li = []
for i in range(len(p)-k+1):
    temp = 0
    for j in range(k):
        temp+=p[i+j]
    counter_li.append(temp)

print(max(counter_li)/2+k/2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, k = map(int, input().split())
arr = np.array([int(i) for i in input().split()])

max = t = sum(arr[0:k])
max_p = sum([_*(_+1)/(_*2.0) for _ in arr[0:k]])

for i in range(1, n-k+1):
  t += arr[i+k-1]
  t -= arr[i-1]
  if max < t:
    max = t
    max_p = sum([_*(_+1)/(_*2.0) for _ in arr[i:i+k]])

print(max_p)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
goukei = 0
ind = 0
kitai = 0

for i in range(k):
    goukei = goukei + p[i]

list = [goukei]

for j in range(1, n-k+1):
    list.append(list[j-1] - p[j-1] + p[j+k-1])

ind = list.index(max(list))

for j in range(ind, ind+k):
    for i in range(1,p[j]+1):
        kitai = kitai + i/p[j]
'''
print(max(list))
print(p)
print(list)
print(ind)
'''
print(kitai)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int,input().split()))
for i in range(N-K+1):
  sum_ = 0
  for k in range(K):
    num = P[i+k]
    sum_ += num*(num+1)/2/num
  if i == 0:
    ans = sum_
  else:
    if sum_ > ans:
      ans = sum_
    else:
      continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
numbers = input().split(" ")
n = int(numbers[0])
k = int(numbers[1])
dices_input = input().split(" ")
dices = []
for i in dices_input:
    dices.append((int(i)+1)*0.5)

expected = []
for j in range(n-k+1):
    ex = 0
    for x in range(k):
        ex += dices[j + x]
    expected.append(ex)
print(max(expected))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k = (int(x) for x in input().split())
p = np.array([int(x) for x in input().split()])

max_val = 0
for i in range(0, p.shape[0]-k+1):
  tmp = p[i:i+k]
  val = np.sum([np.sum([x for x in range(1, t+1)]) / t for t in tmp])
  
  if max_val < val:
    max_val = val

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
arr = input().split(" ")
N = int(arr[0])
K = int(arr[1])

input_arr = input().split(" ")
arr = []

def calc_expected(pi):
    out = 0
    for i in range(1, pi+1):
        out += i
    out = out / pi
    return out

max = 0
tmp = 0
for i in range(N):
    pi = int(input_arr[i])
    ex = calc_expected(pi)
    arr.append(ex)
    tmp += ex
    if(i >= K-1):
        if(max <= tmp):
            max = tmp
        tmp -= arr[0]
        arr.pop(0)

print(max)

Submission status: Time Limit Exceeded

Solution code:

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

PP=P
for i in range(N):
    PP[i]=P[i]*0.5+0.5



ans = float(0)
final = 0
repeat = N-K+1
for j in range(repeat):
    ans = 0
    for i in range(K):
        ans = ans+PP[i+j]
        if final <= ans:
            final = ans
        
print(final)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

#sumを呼び出す
def my_sum(i, k):
    return ((np_p[i:i+k]+1)/2).sum()

def main3():
    ans = 0
    for i in range(n-k+1):
        ans = max(ans, my_sum(i, k))
    print(ans)

main3()

Submission status: Time Limit Exceeded

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

# kitaichi_p_list = [(p + 1)/2 for p in p_list]

max_sum = 0
for i in range(N):
    tmp_sum = sum(p_list[i:i+K])
    if(max_sum < tmp_sum):
        max_sum = tmp_sum
        ichi = i

kitaichi = [(p+1)/2 for p in p_list[ichi:ichi+K]]

print(sum(kitaichi))

Submission status: Time Limit Exceeded

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

ans_max = 0
for i in range(n - k + 1):
    temp = 0
    for j in range(i, i + k):
        temp += (p[j] * (p[j] + 1) / 2) / p[j]

    if(ans_max < temp):
        ans_max = temp

print(ans_max)

Submission status: Time Limit Exceeded

Solution code:
import sys
from pprint import pprint

def solve(n, k, p):
    E = {}
    p_map = {}
    for i, p_i in enumerate(p):
        E[p_i] = (1.0 + p_i)/2
        p_map[i] = p_i
    # pprint(E)
    
    ans = 0
    for i in range(n - k + 1):
        tmp_E = 0
        for j in range(k):
            tmp_E += E[p_map[i+j]]
        ans = max(ans, tmp_E)
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)

Submission status: Time Limit Exceeded

Solution code:
import collections

N,K=map(int,input().split())
P=list(map(int,input().split()))
cnt=0
tmp=0
ans=0
count=0
for i in range(N-K+1):
	#print(P[i:i+K])
	if cnt<sum(P[i:i+K]):
		cnt=sum(P[i:i+K])
		tmp=i
	else:
		cnt=cnt
	#print(cnt)
Q=P[tmp:tmp+K]
count=collections.Counter(Q)
C_K=list(count.keys())
C_V=list(count.values())
R=len(count)
for i in range(R):
	ans+=(C_K[i]*(C_K[i]+1)/(2*C_K[i])*C_V[i])
print(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()]

s_max = 0

p_sum = [sum(p[i:i+k]) for i in range(n-k+1)]

s_max = (max(p_sum) + k) / 2

print(s_max)

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 = 0
for i in range(N-K+1):
    s = (K+ np.sum(P[i:i+K]))/2
    if s > ans:
        ans = s
print(ans)