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:
x = list(map(int, input().split()))
y = list(map(int, input().split()))
y = [i/2+0.5 for i in y]
max_value = 0
for i in range(0, x[0]-x[1]+1):
  value = sum(y[i:i+x[1]])
  max_value = max(max_value, value)
print(max_value)

Submission status: Time Limit Exceeded

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

E = [(p+1)/2 for p in P]

M = 0
for i in range(0, N-K+1):
    exp = sum(E[i:i+K])
    if M < exp:
        M = exp

print(M)

Submission status: Time Limit Exceeded

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
for j in range(n-k+1):
    l = expect_list[j:j+k]
    p = sum(l)
    if p > answer:
       answer = p

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
lst = list(map(int, input().split()))
exp = []
ans = []

a=0
for i in lst:
    a = (i+1)/2
    exp.append(a)

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    l = []
    for i in range(K):
        l.append((p[i]*(p[i]+1))//2/p[i])
    ans = sum(l)
    for i in range(K, N):
        l[i%K] = (p[i]*(p[i]+1))//2/p[i]
        tmp = sum(l)
        if ans < tmp:
            ans = tmp
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


import numpy as np

N,K=acinput()
p=np.array(acinput())


res=0

for i in range(N-K+1):
    tmp = (p[i:(i+K)]+1)/2
    res = max(res, np.sum(tmp))


print(res)

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())))
p += 1
max_ans = 0
for i in range(n-k+1):
    max_ans = max(max_ans, np.sum(p[i:k+i]))
print(max_ans/2)

Submission status: Time Limit Exceeded

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

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

print(ans1)

Submission status: Time Limit Exceeded

Solution code:
''' Hey stalker :) '''
INF = 10**10
def main():
    #print = out.append
    ''' Cook your dish here! '''
    n, k = get_list()
    li = get_list()
    ans = 0
    for i in range(n-k+1):
        ans = max(ans, sum(li[i:i+k]))
    print((ans+k)/2)



''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K = mis()
    import numpy as np
    p = np.array(lmis())
    o = np.ones((K,))
    print(np.max(np.convolve(p, o, mode='valid')+K)/2)


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[]
for i in range(n-k+1):
    for j in range(i,k+i):
        count+=(p[j]/2+0.5)

    ans.append(count)
    count=0
print(max(ans))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

maxx = 0
for i in range(n - k + 1):
    x = 0
    for j in range(k):
        x += sum(a + 1 for a in range(p[i + j])) / p[i + j]
    maxx = max(maxx, x)
print(maxx)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ls = list(map(int,input().split()))
ls = [(x+1)/2 for x in ls]

m = 0

for i in range(n-k+1):
  m = max(m, sum(ls[i:i+k]))
print(m)

Submission status: Time Limit Exceeded

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

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

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

print(max_)

Submission status: Time Limit Exceeded

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

anses = []
for i in range(n - k + 1):
  ans = 0
  for e in p[i:i + k]:
    ans += (e + 1) / 2
  anses.append(ans)
print(max(anses))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
fact = [0]*1010
for i in range(1, 1010): fact[i] = fact[i-1]+i

n, k, *a = map(int, open(0).read().split())
ans = 0
for i in range(n-k+1):
    tmp = 0
    for j in a[i:i+k]: tmp += fact[j]/j
    ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# きりみんちゃんの配信をみてたので期待値は分かる
n, k = map(int, input().split())
arr = list(map(int, input().split()))
lis = [0 for _ in range(n)]
for i in range(n):
    lis[i] = sum(list(range(1, arr[i] + 1))) / arr[i]
ans = 0
for i in range(0, n - k + 1):
    ans = max(ans, sum(lis[i : i + k]))
print(ans)

Submission status: Time Limit Exceeded

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

M = [(1+p)/2 for p in P]
result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N, K = map(int, input().split())
P = list(map(int, input().split()))
# P.sort(reverse=True)
l = []
for i in range(N):
    l.append((P[i]+1) / 2)
ans = 0
for i in range(N-K+1):
    ans = max(ans, sum(l[i:i+K]))
print(ans)

Submission status: Time Limit Exceeded

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

def e(x):
    x = int(x)
    return sum(range(1, x+1)) / x

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = map(int,input().split())
p = list(map(int,input().split()))
e = [(p[i]+1)/2. for i in range(N)]
s = [sum(e[0:i]) for i in range(N+1)]
f = [(s[i+K]-s[i]) for i in range(N-K+1)]
print(max(f))

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from collections import deque

N,K = II()
p = III()
x = [(p0+1)/2 for p0 in p]

d = deque(x[:K])
ans = sum(d)
for i in range(K,N):
    d.popleft()
    d.append(x[i])
    now = sum(d)
    if now>ans:
        ans = now

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

def Ex(p):
    exp=0
    for i in range(1,p+1):
        exp+=i/p
    return exp
E=[Ex(pi) for pi in p]

retval=0
for i in range(N):
    retval=max(sum(E[i:i+K]),retval)

print(retval)

Submission status: Accepted

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

sum_num = sum(nums[:K])
max_num = sum_num

for i in range(1, N - K + 1):
  sum_num = sum_num - nums[i - 1] + nums[i + K - 1]
  if sum_num > max_num:
    max_num = sum_num
    
print((max_num + K) / 2)

Submission status: Accepted

Solution code:
def calc_ex(P):
    sum = 0
    for p in range(1, P+1):
        sum += p
    return sum / P

def main():
    N, K = map(int,input().split())
    P = list(map(int,input().split()))
    accumP = [0] * (N + 1)
    for i in range(N):
        accumP[i+1] = accumP[i] + P[i]

    # 最大の区間を求める
    idx = 0
    sum = accumP[idx+K] - accumP[idx] 
    for i in range(0, N-K+1):
        if accumP[i+K] - accumP[i] > sum:
            idx = i
            sum = accumP[i+K] - accumP[i]
    
    
    ans = 0
    for i in range(idx, idx+K):
        ans += calc_ex(P[i])

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    n,k = map(int,input().split())
    p = tuple(map(int,input().split()))
    s = [(i+1)/2 for i in p]
    a = sum(s[:k])
    ans = a
    for i in range(1,n-k+1):
        a = a - s[i-1] + s[k+i-1]
        ans = max(ans,a)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
def main():

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

    ex = [0]
    for x in p:
        ex.append(ex[-1] + (x+1)/2)

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

    print(ans)

main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
lst = list(map(int,input().split()))
E = [0]
for x in lst:
  E.append((1+x)/2+E[-1])
s = 0
for i in range(n+1-k):
  if s < E[i+k] - E[i]:
    s = E[i+k] - E[i]
print(s)

Submission status: Accepted

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

for i in range(n):
    e.append(p[i] + 1)

sum_e = [0]

for i in range(1,n+1):
    sum_e.append(sum_e[i-1]+e[i-1])

ans = []

for i in range(n-k+1):
    ans.append(sum_e[i+k]-sum_e[i])

print(max(ans)/2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

n, k = inpl()
p = inpl()

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

sm = 0
for i in range(k):
    sm += p[i]
idx = 0

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

print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

s = [0]*(n+1)

for i in range(n):
    s[i+1] = s[i] + p[i]
    
res = 0
for i in range(n-k+1):
    res = max(res,s[i+k]-s[i])
print(res/2)

Submission status: Accepted

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

Submission status: Accepted

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

if n==k:
    ans = 0
    for i in li:
        ans += i*0.5+0.5
    print(ans)
    exit()

K = sum(li[:k])
ans = K
t = 0
for i in range(n-k):
    K += li[i+k] - li[i]
    if K > ans:
        ans = K
        t = i
ans = 0
for i in range(k):
    ans += li[t+i+1]*0.5 + 0.5
print(ans)

Submission status: Accepted

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

#あまり深く事を考えずに
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

d_tmp = sum(p[0:k])
d_max = sum(p[0:k])
for i in range(n-k):
  d_tmp = d_tmp + p[k+i] - p[i]
  d_max = max(d_max,d_tmp)

ans = (d_max + k)/2
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
T = [0]*N

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

if N == K:
    print(sum(P))

else:
    for i in range(1,N):
        P[i] += P[i-1]

    for i in range(K,N):
        T[i] = P[i] - P[i-K]

    T = T[K:]

    print(max(T))

Submission status: Accepted

Solution code:
import copy
n, k = map(int, input().split())
P = list(map(int, input().split()))
U = [0]*n

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

ans = sum(U[:k])
t = copy.copy(ans)

for i in range(n-k):
    t =  t+U[k+i]-U[i]
    ans = max(ans, t)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for k in range(K):
    ans+=(1+p[hoge+k])/2

print(ans)

Submission status: Accepted

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

P[0] = (P[0]+1.)/2
for i in range(1,len(P)):
    P[i] = (P[i]+1.)/2
    P[i] = P[i-1]+P[i]

ans = 0.

if n==1:
    ans = P[0]

elif len(P)-k==0:
    ans = P[k-1]
else:
    for i in range(len(P)-k):
        ans = max(ans,(P[i+k]-P[i]))
        
    
print(ans)

Submission status: Accepted

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

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

q = [0]
for i in range(n):
    q.append(ev(p[i]))
    q[i + 1] = q[i] + ev(p[i])
#print(q)

tmp = 0
for j in range(n - k + 1):
    if tmp <= q[j + k] - q[j]:
        tmp = q[j + k] - q[j]
print(tmp)

Submission status: Accepted

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

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

def main():
    mod=10**9+7
    N,K=MI()
    P=LI()
    S=[0]*(N+1)
    
    for i in range(N):
        S[i+1]=S[i]+P[i]
        
    M=0
    for i in range(N-K+1):
        temp=S[K+i]-S[i]
        M=max(M,temp)
        
    ans=(M+K)/2
    print(ans)

main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
Q = sum(P[:K])
R = Q

for n in range(N-K):
  Q = Q-P[n]+P[n+K]
  R = max(Q,R)

print((R+K)/2)

Submission status: Accepted

Solution code:
from numpy import *
N,K = map(int,input().split())
P = list(map(int,input().split()))
Q = (N-K+1)*[0]
R = sum(P[0:K])
Q[0] = R

for n in range(1,N-K+1):
  R+=P[n-1+K]-P[n-1]
  Q[n] = R

S = argmax(Q)
print(0.5*(sum(P[S:S+K])+K))

Submission status: Accepted

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

E = []

for i in range(N):
    E.append((P[i]+1)/2)

tnt = sum(E[:K])
ans = tnt

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

print(ans)

Submission status: Accepted

Solution code:

def main():
    n, k = map(int, input().split(" "))
    p = list(map(int, input().split(" ")))
    u = [0]
    v = []
    w = []
    for i in range(n):
        u.append(u[i]+p[i])
    for i in range(n-k+1):
        w.append(u[k+i]-u[i])
    x = w.index(max(w))
    for i in range(k):
        v.append(p[x+i])
    a=0
    for i in range(k):
        a += 1+0.5*(v[i]-1)
    print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

total = [0] * N
total[0] = p[0]
for i in range(1, N):
  total[i] = total[i-1] + p[i]

total_K = 0
max_i = 0
for i in range(N-K+1):
  if i == 0:
    total_K = total[K-1]
  else:
    if total[i+K-1] - total[i-1] > total_K:
      total_K = total[i+K-1] - total[i-1]
      max_i = i

ans = 0
for i in range(K):
  ans += (p[max_i + i] + 1) / 2
print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
    N, K = MI()
    P = LI()
    a = sum(P[0:K])
    Sums = []
    Sum = 0
    for i in range(N):
        Sum += P[i]
        Sums.append(Sum)
    ans = [a, 0, K - 1]
    for i in range(K, N):
        X = Sums[i] - Sums[i - K]
        if X > ans[0]:
            ans[0] = X
            ans[1] = i - K + 1
            ans[2] = i
    cnt = 0
    for i in range(ans[1], ans[2] + 1):
        cnt += (P[i] + 1) / 2
    print(cnt)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int,input().split()))
q = [(x+1)/2 for x in p]
q1 = sum(q[:k])
ans = q1

for i in range(n-k):
  x = q1-q[i] +q[i+k]
  q1 = x
  if ans < x:
    ans = x
  
print(ans)

Submission status: Accepted

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

res=0
s=sum(p[:K])
for i in range(N-K+1):
    res=max(res,(s+K)/2)
    if i!=N-K:
        s=s+p[i+K]-p[i]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
List = list(map(int, input().split()))
INF = 10000000000
expList = [INF]*1001
def expectationF(num):
  if expList[num] == INF:
    exp = 0
    for i in range(1,num+1):
      exp += i/num
    expList[num] = exp
  return expList[num]

res = 0
mid = 0
midList=[]
for i in range(N):
  if i>=1:
    midList.append(expectationF(List[i])+midList[i-1])
  else:
    midList.append(expectationF(List[i]))
m=K-1
for j in range(N-m):
  if j == 0:
    mid = midList[j+m]
  else:
    mid = midList[j+m]- midList[j-1] 
  res = max(res,mid)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    p_lst = list(map(int, input().split()))
    lst = []

    for i in range(n):
        lst.append((p_lst[i] + 1) / 2)

    tmp_sum = sum(lst[:k])
    maximum = tmp_sum
    for i in range(n - k):
        tmp_sum -= lst[i]
        tmp_sum += lst[i + k]
        maximum = max(maximum, tmp_sum)

    print(maximum)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dice_expectation(p):
  return ((1 + p) * p / 2) * (1/p)

n, k = map(int, input().split())
pp = [0] * (n+1)
for i, p in enumerate(map(int, input().split())):
  pp[i+1] = pp[i] + dice_expectation(p)

max = -1
for i in range(k, n+1, 1):
  max = pp[i] - pp[i-k] if pp[i] - pp[i-k] > max else max

print(max)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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
  
ans=[0]*(N-K+1)
ans[0]=sum(p[:K])
for i in range(1, N-K+1):
  ans[i]=ans[i-1]-p[i-1]+p[i+K-1]

print(max(ans))

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n, k = i_map()
    p = i_list()


    sowa = [0]
    for i in range(1,1001):
        sowa.append(sowa[i-1]+i)

    l = [sowa[p[0]]/p[0]]

    for i in range(1,n):
        l.append(l[i-1] + sowa[p[i]]/p[i])


    ans = l[k-1]
    for i in range(k,n):
        s = l[i] - l[i-k]
        ans = max(ans,s)
    print(ans)


if __name__=="__main__":
    main()

Submission status: Accepted

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

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

lis=[0]*(n+1)
for i in range(n):
  lis[i+1]=lis[i]+l[i]
  
ans=0
for i in range(n-k+1):
  num=lis[i+k]-lis[i]
  ans=max(num,ans)
  
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    import numpy as np

    N, K = map(int, input().split())
    P = np.array(input().split(), np.int32)

    P[:] += 1
    Pcum = np.zeros(N + 1, np.int32)
    Pcum[1:] = np.cumsum(P)
    length_K_sums = Pcum[K:] - Pcum[:-K]
    print(length_K_sums.max() / 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():

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

    current = sum(A[:K])
    ans =(current+K)/2

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    def expected_val(limit):
        # return (1 + limit) / 2
        return sum(range(limit + 1)) / limit

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

    lst = [0]
    res = 0
    for p in P:
        res += expected_val(p)
        lst.append(res)
    ans = 0
    for i in range(N - K + 1):
        res = lst[i + K] - lst[i]
        ans = res if res > ans else ans
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    def expected_val(limit):
        return (1 + limit) / 2

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

    lst = [0]
    res = 0
    for p in P:
        # res += (p + 1) / 2
        res += expected_val(p)
        lst.append(res)
    ans = 0
    for i in range(N - K + 1):
        res = lst[i + K] - lst[i]
        ans = res if res > ans else ans
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    def expected_val(limit):
        return (1 + limit) / 2

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

    lst = [0]
    res = 0
    for p in P:
        res += (p + 1) / 2
        lst.append(res)
    ans = 0
    for i in range(N - K + 1):
        res = lst[i + K] - lst[i]
        ans = res if res > ans else ans
    print(ans)


if __name__ == '__main__':
    main()