Problem:


Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000



Sample input:
5 3
1 2 2 4 5


Sample output:
7.000000000000

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()
    P = LIST()

    L = []
    for i in range(N-K+1):
        tmp = 0
        for j in range(K):
            tmp += P[i+j] * 0.5 + 0.5
        L.append(tmp)

    print(max(L))


if __name__ == '__main__':
    main()

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)):
        result = 0
        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 sum(range(x+1))/x

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
ps = list(map(lambda n: (int(n)+1)/2, input().split()))

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:
def sums(N):
  return 1 + (N-1) * 0.5

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

exp = [0 for _ in range(N)]
for i in range(0, N):
  exp[i] = sums(Ps[i])

ans = [0 for _ in range(N)]

for i in range(0, K):
  ans[K-1] += exp[i]

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


print(ans[N-1])

Submission status: Time Limit Exceeded

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

t = [0]*n
for i in range(n-(k-1)):
    for j in range(i,i+k):
        t[i] += p[j]
T = t.index(max(t))
ans = 0
for i in range(k):
    ans += (p[T+i]+1)/2
print(ans)

Submission status: Time Limit Exceeded

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

def sum_element(p:list,i:int,k:int):
    ans = 0
    for j in range(k):
        ans += p[i+j]
    return ans

pmax = 0
pindex = 0

for i in range(len(p)-k+1):
    ptmp = sum_element(p,i,k)
    if pmax < ptmp:
        pindex = i
        pmax = ptmp

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
p = [int(s) for s in input().split()]

r = 0
for i in range(N - K + 1):
    r = max(r,sum(p[i:i+K])+K)
    
print("{:.12f}".format(r /2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sums = []
for ind in range(n-k+1):
  sums.append(sum(p[ind:ind+k]))
max_val = float(max(sums))
k = float(k)
print(max_val/2+k/2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np

E = (np.array(P)+1)/2

ans = 0.0
for i in range(K,N+1):
  if sum(E[i-K:i])> ans:
    ans = sum(E[i-K:i])
print(float(ans))

Submission status: Time Limit Exceeded

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

p = np.array(input().split(),np.int)

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


print(ans)

Submission status: Time Limit Exceeded

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

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

def summ(i):
    return i*(i+1)/2

ss = 0


for i in s:
    ss += summ(i)/i

print(ss)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []
m = []
s = []
j = 0
for i in range(1, 1001):
    j += i
    s.append(j)

for i in range(n-k+1):
    l.append(p[i:i+k])
    m.append(sum(p[i:i+k]))
Max_index = m.index(max(m))

ll = l[Max_index]
ans = 0
for i in ll:
    ans += s[i-1]/i 
print(ans)

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]
S = 0
for i in range(N-K+1):
  temp = sum(E[i:i+K])
  if S < temp:
    S = temp
  
print(S)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()

def solve():
    ans = 0
    for h in range(N - K + 1):
        partial = 0
        for i in range(h, h + K):
            partial += (p[i] + 1) / 2
        ans = max(ans, partial)
    return ans

if __name__ == "__main__":
    print(solve())

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().rstrip().split())
Ps = [int(x) for x in input().rstrip().split()]
base_i = 0
max_val = 0
for i in range(len(Ps)-K+1):
    sum_val = sum(Ps[i:i+K])
    if max_val < sum_val:
        max_val = sum_val
        base_i = i
print((sum(Ps[base_i:base_i+K])+K)/2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0

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

print(float(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

def kitai(x):
  a = 0
  b = 1
  t = x
  while t > 0:
    a += b
    b += 1
    t -= 1
  return a/x

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)

ans = 0
for i in p[keys[0]:keys[1]]:
  ans += kitai(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def K(n):
    s = 0
    for i in range(1, n+1):
        s += i
    return s / i

def d():
    n, k = input().split()
    n = int(n)
    k = int(k)
    p = input().split()
    p2 = [K(int(o)) for o in p]

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

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A=list(map(int, input().split()))  
num=0
for j in range(0,K):
    num += sum(range(1,A[j]+1))/A[j]  
#num = sum(A[0:K])
#ind = 0
#max_num =0
ans = num
for i in range(N-K):
    num -= sum(range(1,A[i]+1))/A[i] 
    num += sum(range(1,A[i+K]+1))/A[i+K] 
    ans = max(num,ans)


print(ans)

Submission status: Time Limit Exceeded

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

expect_value = [0]*N

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

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

Submission status: Time Limit Exceeded

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

ans=(sum(P[:K])+K)/2
for i in range(1,N-K+1):
    s=(sum(P[i-1:K+i-1])+K)/2
    ans=max(ans,s-(P[i-1]+1)/2+(P[i+K-1]+1)/2)
    
print(ans)

Submission status: Time Limit Exceeded

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

ps_k = [sum(ps[i:i+k]) for i in range(n)]

start = ps_k.index(max(ps_k))

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

Submission status: Time Limit Exceeded

Solution code:
# abc 154
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

def cal_expected(p):
    expected = 0
    for i in range(1, p+1):
        expected += i / p
    return expected

# 期待値一覧の作成
expected_dict = {k:cal_expected(k) for k in set(P)}

# 対象特定
dices = []
dices_sum = 0
for start in range(0, N-K+1):
    tmp_dices = P[start:start+K]
    tmp_sum = sum(tmp_dices)
    if tmp_sum > dices_sum:
        dices = tmp_dices
        dices_sum = tmp_sum

# 期待値計算
# answer = sum(map(cal_expected, dices))
answer = 0
for dice in dices:
    answer += expected_dict[dice]
print(answer)

Submission status: Time Limit Exceeded

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

for i in range(n-k+1):
    if sum(p[i:i+k]) >= a:
        a=sum(p[i:i+k]) 
        b=i

print(sum([(k+1)/2 for k in p[b:b+k]]))

Submission status: Time Limit Exceeded

Solution code:
a, c = map(int, input().split())
r = a - c + 1

d = list(map(lambda x:(int(x)+1)/2, input().split()))

j = 0
for u in range(r):
  g = sum(d[u:u+c])
  if g > j:
    j = g

print(j)

Submission status: Time Limit Exceeded

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

def calc(n,a,l):
  return (a+l)/2

max_e=0
for i in range(N-(K-1)):
  v=p[i:K+i]
  #print(v)
  smin=len(v)
  smax=sum(v)
  kou=smax-(smin-1)
  e=calc(kou,smin,smax)
  #e=list(map(calc, v))
  #print(e)
  #e=sum(e)

  if max_e<e:
    max_e=e

print(max_e)

Submission status: Time Limit Exceeded

Solution code:
arr = [ 0 for x in range ( 1000 +1 ) ] ;
for k in range ( 1 , len( arr  ) ) : 
	arr[k] += ( k * ( k + 1 ) ) / k / 2 ;

N , K = map( int , input().strip().split(" ") ) ; 
LL = list( map( int , input().strip().split(" " ) ) );

m = 0  ;
for r in range ( N ) :
	if r + K > N : break ;
	v = sum ( map ( lambda x:arr[x] , LL[r:r+K] ) ) ; 
	m = max ( m , v) ; 
print ( "{0:.8f}".format(  m ) ) ;

Submission status: Time Limit Exceeded

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

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

ans = 0

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

print((ans + K) / 2)

Submission status: Time Limit Exceeded

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

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

kaisu = n-k + 1
point = 0
res = 0
for j in range(kaisu):
  temp = 0
  for jj in range(k):
    temp += p[jj + j]
  if res < temp:
    res = temp
    point = j

max_p = p[point:point+k]
kitai = [expected_value(i) for i in max_p]
print(sum(kitai))

Submission status: Time Limit Exceeded

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

def Ex(n):
  return sum(range(1,n+1))/n
 
out = [0]*K
_sum = [0]*K
_max = 0
for i in range(N):
  curr = Ex(ps[i])
  tmp = _sum[-1] - out[0] + curr
  _max = max(_max, tmp)
  
  out = out[1:] + [curr]
  _sum = _sum[1:] + [tmp]
print(_max)

Submission status: Time Limit Exceeded

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

PP = [(1 + pp) / 2 for pp in P]

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

print(mm)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

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

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

    print(max([
        sum([
            get_expect(p)
            for p in P[i:i + K]
        ])
        for i in range(N - K + 1)
    ]))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

#初期 
SUM = sum(P[0:K])
M=0

for i in range(N - K + 1):
    _SUM=sum(P[i:i + K])
    if SUM < _SUM:
        SUM = _SUM
        M = i

EXP_V = (K + SUM)/2
print(EXP_V)

Submission status: Time Limit Exceeded

Solution code:
a = []
total = 0
N,K = list(map(int,input().split()))
number_list = list(map(int,input().split()))
for i in range(N-K+1):
    a.append(sum(number_list[i:i+K]))
b = max(a)
a = list(a)
max_pattern = a.index(b)
for r in number_list[max_pattern:max_pattern+K]:
    total += r * (1+r) / (2*r)
print(total)

Submission status: Time Limit Exceeded

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

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

ans = (sum(maxlist)+int(len(maxlist)))/2
print('{:.12f}'.format(ans))

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()]
ls = [0]
ex = [0]
mx = 1001

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:
import sys
from pprint import pprint

def solve(n, k, p):
    E = [(1.0 + p_i)/2 for p_i in p]
    # pprint(E)
    
    ans = 0
    for i in range(n - k + 1):
        ans = max(ans, sum(E[i:i+k]))
    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:
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    P[i] = (1+P[i])/2
A = 0
for i in range(N-K+1):
    B = 0
    for j in range(i,i+K):
        B = B+P[j]
    if A < B:
        A = B
print(A)

Submission status: Time Limit Exceeded

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

q = []
for p_i in p:
  q.append((p_i+1)/2)

max_e = 0
for i in range(n-k+1):
  e = sum(q[i:i+k])
  
  if e > max_e:
    max_e = e

print(max_e)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
listp = tuple(map(int, input().split()))
ans = 0
for n in range(N-K+1):
    b = sum(listp[n:n+K])
    ansc = (b+K)/2
    if ansc > ans:
        ans = ansc
    else:
        pass    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def e(dice):
    return sum([r / dice for r in range(1, dice+1)])

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

p = [0] + list(p)

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

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 = sum(P[i:i+K])
    ans = a if a > ans else ans
print((ans+K)/2)

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)

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
kitai = [(0.5*i*(i+1))/i for i in range(1, 1001)]

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

ans = 0
for al in ans_list:
    ans += kitai[al-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    kakuritsu[i] =  num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    max_sn[i] = sum(kakuritsu[i:i+K]) * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
kitaiti = [0] * n
for i in range(n):
    kitaiti[i] = (p[i]+1) / 2
# 初期値
l = 0
r = k - 1
max = 0
for i in range(n-k+1):
    now = sum(kitaiti[l:r+1])
    l += 1
    r += 1
    if now > max:
        max = now
print(max)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
p = input().split()
ex = [0 for i in range(N)]
E=0
def expectation(n):
    return (n+1)/2
def ran(n,k,i):
    if i+1>=K and N-(i) >= K:
        return K
    elif i+1 < K:
        return i+1
    else:
        return N-i

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


for i in range(N-K+1):
    newE = 0
    for j in range(K):
        newE += ex[i+j]

    if newE > E:
        E = newE

    
    

print(E)

Submission status: Time Limit Exceeded

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

box = [0]*(n-k+2)

for i in range((n-k+2)//2):
    s = sum(P[i:k+i])
    p = sum(P[n-k-i+1:n-i+1])
    box[2*i] = s
    box[2*i+1] = p
su = max(box)
print((su+k)/2)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
diceList=list(map(int,input().split()))
num=0
sum=0
ans=0
for i in range(N):
  num=diceList[i]
  for j in range(num):
    sum+=j+1
  ans=sum/num
  diceList[i]=ans
  sum=0
  ans=0

max=0
st=0
for i in range(N-K+1):
  for j in range(K):
    st+=diceList[i+j]
  if(st>=max):
    max=st
  else:
    pass
  st=0
print(max)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(n-k+1):
  tmp=0
  for j in range(k):
    tmp+=(p[i+j]+1.0)/2.0
  ans = max(ans, tmp)
print('{:.12f}'.format(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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




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

Submission status: Time Limit Exceeded

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

N, K = map(int, input().split())
p = list(map(int, input().split()))
q = []
max = 0
for i in range(N):
    q.append(p[i]*(p[i]+1)/(2*p[i]))
for i in range(N-K+1):
    v = 0
    for j in range(K):
        v += q[i+j]
    if v > max:
        max = v
print(max)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
p=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
ck = []

#最大のリストを選定
for i in range(0,n-k+1):
    ck.append(sum(p[i:i+k]))

#計算
print((max(ck)+k)/2.0)

Submission status: Time Limit Exceeded

Solution code:
N,K = input().split(" ")
N = int(N)
K = int(K)
p = input().split(" ")
expected_list = []
max_list = []
for i in range(N):
  sum = 0
  for j in range(int(p[i])+1):
    sum += j
  expected_list.append(float(sum/(int(p[i]))))
  
for i in range(N):
  anan = 0
  for j in range(K):
    try:
      anan += expected_list[i+j]
    except:
      pass
  max_list.append(anan)

print(max(max_list))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

number_list = []

for p in p_list:
    number_list.append((p * (p + 1)) / 2 / p)

sum_max = 0
for i in range(0, len(number_list)):
    sum_total = sum(number_list[i:i+K])
    if sum_max < sum_total:
        sum_max = sum_total

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

Submission status: Time Limit Exceeded

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

print(sum(map(lambda x: (x+1)/2, P[m_index:m_index+K])))

Submission status: Time Limit Exceeded

Solution code:
t = input().split(" ")

N = int(t[0])
K = int(t[1])

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

for i in range(len(p)):
    #a = list(range(1,p[i]+1))
    #print(a)
    p[i] = sum(list(range(1,p[i]+1)))/p[i]
#    print(p[i])

ans = 0
for i in range(N-K+1):
    
    a =0
#    print(i)
    for j in range(K):
#        print(p[i+j])
        a += p[i+j]

    if a > ans:
        ans = a

print(ans)

Submission status: Time Limit Exceeded

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

# N,K=4 ,1
# s=[6 ,6 ,6 ,6 ]
# list_a=[]
# list_b=[]
S=0
for i in range(len(s)-K+1):
#     list_a.append(s[i:i+K])
#     list_b.append(sum(s[i:i+K]))
    if S<sum(s[i:i+K]):
        S=sum(s[i:i+K])


print((S+K)/2)

Submission status: Time Limit Exceeded

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

b=0

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

for i in range(n-k+1):
  t=sum(s[i:i+k])
  if t>b:
    b=t
print((b+k)/2)

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)

keep_val = 0
check = 0
for i in range(n-k+1):
    ss = np_p[i:i+k].sum()
    if keep_val < ss:
        check = i
        keep_val = ss
print(((np_p[check:check+k]+1)/2).sum())

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

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

i = np.argmax(ppp)

tmp = p[i:i+K]
m=0
for t in tmp:
  m += 0.5*(t+1)
print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def n_gram(target, n):
  # 基準を1文字(単語)ずつ ずらしながらn文字分抜き出す
  return [target[idx:idx + n] for idx in range(len(target) - n + 1)]


N_K = LIST()
P = LIST()

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

n_gram_P = n_gram(P, K)

max = 0
max_list = []
for n in n_gram_P:
    tmp = sum(n)
    if tmp > max:
        max = tmp
        max_list = n

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
kouho=[]
def saikorokitaiti(A):
    return ((P[A]*(1+P[A])/2)/P[A])
hako=[]
for i in range(N-K+1):
    for j in range(K):
        hako.append(saikorokitaiti(i+j))
        if j==K-1:
            kouho.append(sum(hako))
            hako=[]

print(max(kouho))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
e = [0]*n

for i in range(n) :
    e[i] = (p[i] + 1.0)/2.0

emax = 0
for j in range(n-k+1) :
    enow = sum(e[j:j+k])
    emax = max(enow,emax)

print(emax)

Submission status: Time Limit Exceeded

Solution code:
def get_ex(l):
  return (sum(l) + len(l)) / 2
  
n, k = map(int, input().split())
p = [int(p_i) for p_i in input().split()]

ex_values = [get_ex(p[i:k+i]) for i in range(n-k+1)]
print(max(ex_values))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=[int(_) for _ in input().split()]
for i in range(n):
  s=0
  for x in range(1,p[i]+1):
    s+=x
  p[i]=float(s/p[i])
ans=0
for i in range(n-k+1): 
  tmp=0
  '''
  for j in range(k):
    tmp+=e[i+j]
  '''
  tmp=sum(p[i:i+k])
  if ans<=tmp:
    ans=tmp
print(ans)

Submission status: Time Limit Exceeded

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

#初期 
SUM = sum(P[0:K])
M=0

for i in range(N - K + 1):
    if SUM < sum(P[i:i + K]):
        SUM = sum(P[i:i + K])
        M = i

EXP_V = (K + SUM)/2
print(EXP_V)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

S = []
max_num = 0
for i in range(N):
    if i+K <= N:
        tmp = sum(P[i:i+K])
        if tmp  > max_num:
            max_num = tmp
            S = P[i:i+K]
    else:
        break

ans = 0
for i in range(len(S)):
    gausu = (S[i])*(S[i]+1)/2
    ans += (gausu/S[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split()) 
p = list(map(float, input().split()))
n_e = n - k + 1
e = [0] * n_e
for i in range(n_e):
  tot = 0
  for j in range(k):
    tot += (p[i+j]*1.0 + 1.0) * 0.5
  e[i] = tot
ans = "{0:.10f}".format(max(e))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[0]*k
ans=0
for i in range(k):
    a[i]=p[i]
ans=sum(a)
for i in range(n):
    a.remove(a[0])
    a.append(p[i])
    if ans<sum(a):
        ans=sum(a)
print((ans+k)*0.5)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# = int(input())
n,k = [int(x) for x in input().split()]
ps = [int(x) for x in input().split()]
for i in range(n):
    ps[i] = (ps[i]+1)/2
psk = []
def kitaichi(m):
    ret = 0
    for j in range(m,m+k):
        ret += ps[j]
    return ret
mx = 0
for i in range(n-k+1):
    if mx < kitaichi(i):
        mx = kitaichi(i)
print(mx)

Submission status: Time Limit Exceeded

Solution code:
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 = []
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.pop(0)

print(max_sum)

Submission status: Time Limit Exceeded

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

def calc_exp(n):
    exp=1+(n-1)*0.5
    return exp

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

Submission status: Time Limit Exceeded

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

#連続するK個の要素の和で一番大きいもの
start = -1
maximum = -1
for i in range(len(p) - k + 1):
  temp = sum(p[i:i + k])
  if temp > maximum:
    maximum = temp
    start = i

#期待値の算出
exp = 0
for i in range(start, start + k):
  temp = 0
  for j in range(1, p[i] + 1):
    temp += j
  exp += temp / p[i]

print(exp)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int, input().split())
a= list(map(int, input().split()))
maxans=0
for i in range(len(a)):
  ans=sum(a[i:i+k])
  maxans=max(ans,maxans)
print((maxans+k)/2)