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: Accepted

Solution code:
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n, k = [int(x) for x in input().split()]
    p = [int(x) for x in input().split()]
    s = 0
    for i in range(k):
        s += p[i]
    max_sum = s
    for i in range(n-k):
        s += p[k+i] - p[i]
        max_sum = max(s, max_sum)
    return (max_sum + k) / 2


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

Submission status: Accepted

Solution code:
from itertools import accumulate

n, k = map(int, input().split())
e = [(int(i) + 1) / 2 for i in input().split()]
a = list(accumulate(e))
s = [a[i + k] - a[i] for i in range(n - k)]
print(max(a[k - 1], *s) if n > k else a[-1])

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,k,*ppp = get_all_int()

sum_ = sum(ppp[:k])
maxs = sum_
maxt = 0

tail = 0
while tail+k < len(ppp):
    sum_ -= ppp[tail]
    sum_ += ppp[tail+k]
    tail += 1
    if sum_ > maxs:
        maxs = sum_
        maxt = tail

ans = 0
for p in ppp[maxt:maxt+k]:
    ans += (p+1)/2

print(ans)

Submission status: Accepted

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

mxidx = 0
mx = 0
tot=0
for i in range(k):
    tot+=p[i]
mx=tot
for i in range(k,n):
    tot+=p[i]-p[i-k]
    if tot>mx:
        mxidx=i-k+1
        mx=tot

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

print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    P = [int(p) for p in input().split()]
    Ex = [0] * N
    for i, p in enumerate(P):
        total = (p + 1) * p / 2
        Ex[i] = total / p
    maxEx = sum(Ex[:K])
    now = maxEx
    for i in range(N - K):
        now -= Ex[i]
        now += Ex[i + K]
        maxEx = max(maxEx, now)
    print(maxEx)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	P = getlist()
	B = [0] * (N + 1)
	for i in range(N):
		B[i + 1] = B[i] + P[i]
	# print(B)
	ans = 0
	for i in range(N - K + 1):
		val = B[i + K] - B[i]
		ans = max(ans, val)

	ans = (ans + K) / 2
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



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


print(ans)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
p = inpl()
maxsum = sum(p[:K])
s = maxsum
for i in range(N-K):
    s += p[i+K]-p[i]
    if s > maxsum:
        maxsum = s
print((maxsum+K)/2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
P_sum = [0]
for p in P:
    P_sum.append(P_sum[-1] + p)

max_sum, max_P = 0, None
for i in range(N - K + 1):
    if max_sum < P_sum[i + K] - P_sum[i]:
        max_sum = P_sum[i + K] - P_sum[i]
        max_P = P[i:i + K]

print(sum([(p * (p + 1) // 2) / p for p in max_P]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC154d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

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

    def cum(array):
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    def calc(N):
        t = 0
        for i in range(1, N+1):
            t += i / N
        return t

    p2 = cum(p)

    for i in range(n - k+1):
        if ans < p2[i+k]-p2[i]:
            ans = p2[i+k]-p2[i]
            pos = i

    ans = 0
    for i in range(pos, pos + k):
        ans += calc(p[i])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
P_acc = list(accumulate(P))


M = 0
Mi = -1
for i in range(1, N - K + 2):
    if P_acc[i + K - 1] - P_acc[i - 1] > M:
        M = P_acc[i + K - 1] - P_acc[i - 1]
        Mi = i


ans = 0
for i in range(Mi, Mi + K):
    ans += ((1 + P[i]) * 0.5 * P[i]) / P[i]

print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
p = LI()
lst = [(i+1)/2 for i in p]
l = [0]+ list(accumulate(lst))
ans = 0
for i in range(n-k+1):
    ans = max(ans,l[i+k] - l[i])
print(ans)

Submission status: Accepted

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

maxind=-1
cur=sum(P[:K])
maxval=cur
for i in range(K,N):
  cur=cur+P[i]-P[i-K]
  if cur>maxval:
    maxval=cur
    maxind=i

# i-K+1～iまでの期待値を求める
ans=0
for i in range(maxind-K+1,maxind+1):
    ans+=(P[i]*(P[i]+1)//2)/P[i]
    
print(ans)

Submission status: Accepted

Solution code:

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

p2 = [(i+1)/2 for i in p]

ans = sum(p2[:K])
tmp = ans
idx = 0
while idx<N-K:
    tmp += p2[idx+K]
    tmp -= p2[idx]
    ans = max(ans,tmp)
    idx += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
#n = int(readline())
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))
memo = [0]
for i in range(1,1001):
    memo.append(memo[-1]+i)
for i in range(1,1001):
    memo[i] /= i 

for i in range(len(lst1)):
    lst1[i] = memo[lst1[i]]

p = sum(lst1[:k])
ans = 0
for i in range(n-k+1):
    ans = max(ans,p)
    if i + k >= len(lst1):
        break 
    p -= lst1[i]
    p += lst1[i+k]

print(ans)

Submission status: Accepted

Solution code:
from bisect import *
from collections import *
from fractions import gcd

N,K=map(int,input().split())
P=list(map(int,input().split()))
value=0
for i in range(K):
    value+=(P[i]*(P[i]+1)//2)/P[i]
maxvalue=value
for i in range(N-K):
    value-=(P[i]*(P[i]+1)//2)/P[i]
    value+=(P[i+K]*(P[i+K]+1)//2)/P[i+K]
    maxvalue=max(value,maxvalue)
print(maxvalue)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:

def resolve():
    N,K=map(int,input().split())
    P=[int(i) for i in input().split()]
    PP= [i*(i+1)/2/i for i in P]
    mx = sum(PP[:K])
    sm=mx
    for i in range(K,N):
        sm+=PP[i]
        sm-=PP[i-K]
        mx=max(sm,mx)
    print(mx)





if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + ans[i]
    
res = 0
for i in range(n):
    if k+i > n:
        break
    res = max(res, ruiseki[k + i] - ruiseki[i])
print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(float,input().split()))
Q = list(map(lambda x: (x+1)/2,P))

S = sum(Q[:K])
ans = S

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def e(a):
        return ((a*(a+1))>>1)/a
    n,k = LI()
    p = LI()
    p = [e(i) for i in p]
    ans = m = sum(p[:k])
    for i in range(n-k):
        m -= p[i]
        m += p[i+k]
        if ans < m:
            ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n, k=map(int, input().split())
plist = list(map(int, input().split()))
now=sum(plist[:k])
answer=now
#print(now)
for i in range(n-k):
    now-=plist[i]
    now+=plist[i+k]
    if now>=answer:
        answer=now

print((k+answer)/2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = map(int, input().split())
pl = list(map(int, input().split()))

ppl = [0]*n
for i in range(n):
    ppl[i] = (pl[i]+1)/2

acc = [0]*(n+1)
for i in range(n):
    acc[i+1] += acc[i]+ppl[i]

res = -1
for i in range(n-k+1):
    res = max(res, acc[i+k]-acc[i])

print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p = list(map(int,input().split()))
current_sum = sum(p[:k])
ans = current_sum
for x,y in zip(p,p[k:]):
    current_sum += y - x
    ans = max(ans,current_sum)
print((ans+k)/2)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

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

def main():
    N, K = LI()
    p = LI()
    p = [ki(x) for x in p]
    cursum = sum(p[:K])
    ans = cursum
    i = K
    for i in range(K, N):
        cursum -= p[i-K]
        cursum += p[i]
        ans = max(cursum, ans)
    print(ans)
main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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


def f(x):
    return (1 + x) / 2


kitai = [0] + [f(e) for e in p]
acm = list(accumulate(kitai))

ans = 0
for e1, e2 in zip(acm, acm[k:]):
    ans = max(ans, e2 - e1)

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate

    n, k = map(int, input().split())
    *p, = ((float(x) + 1) / 2 for x in input().split())

    acc = (0,) + tuple(accumulate(p))

    ret = 0
    for i in range(k, n + 1):
        ret = max(ret, acc[i] - acc[i - k])
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

Submission status: Accepted

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

ps = list(map(int, input().split()))
cur = 0
for i in range(k):
    cur += ps[i] + 1

mx = cur

for i in range(n-k):
    j = i+k
    cur += -ps[i] + ps[j]
    mx = max(mx, cur)

print(mx / 2)

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    max_val = 0
    val = 0
    for i in range(n):
        val += A[i]
        if i >= m:
            val -= A[i-m]
        if i >= m - 1:
            max_val = max(max_val, val)
    max_val = (max_val + m) / 2
    print('%.10f' % max_val)

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

Submission status: Accepted

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

Q = [p+1 for p in P]

S = [sum(Q[:K])]
for m,p in zip(Q[:N-K],Q[K:]):
    S.append(S[-1]+p-m)
ans = max(S)/2
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
t = sum(P[:K])
ans = t
for i in range(K, N):
  t = t - P[i-K] + P[i]
  ans = max(ans, t)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

window = deque()
ev = 0
best = 0
for p in P:
    if len(window) == K:
        old = window.popleft()
        ev -= (old + 1) / 2
    window.append(p)
    ev += (p + 1) / 2
    best = max(best, ev)

print(best)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    m = t = sum(p[:K])
    for i in range(N-K):
        t -= p[i]
        t += p[i + K]
        m = max(m, t)
    return (m + K)/2
print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import itertools 
n,k = map(int,input().split())
A = list(map(int,input().split()))
B = [ (i+1)/2 for i in A]
C = [0] + list(itertools.accumulate(B))
ans = 0
for i in range(n + 1 - k):
    ans = max(ans,C[i+k]-C[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, K = map( int, input().split())
    P = list( map( int, input().split()))
    now = sum(P[:K])
    ans = now
    for i in range(K,N):
        now -= P[i-K]
        now += P[i]
        if now > ans:
            ans = now
    print((ans+K)/2)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = map(int, raw_input().split())
p = map(int, raw_input().split())
for i in range(N):
    p[i] += 1
    p[i] /= 2.0
S = 0.0
for i in range(K):
    S += p[i]
ans = S
for i in range(K, N):
    S += p[i]
    S -= p[i - K]
    ans = max(ans, S)
print "%.5f" % ans

Submission status: Accepted

Solution code:
N ,K = map(int,input().split())
P = list(map(int,input().split()))
A = P[:K]
a = sum(A)
max = a
for i in range(N-K):
    a = a-P[i]+P[i+K]
    if max <= a:
        max = a
print((max+K)/2.0)

Submission status: Accepted

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

s = 0
for i in range(K):
    s += A[i] + 1

ma = s
for i in range(K, N):
    s += A[i] + 1
    s -= A[i-K] + 1
    ma = max(ma, s)

print(ma / 2)

Submission status: Accepted

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

from itertools import accumulate

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

A = [(a + 1) / 2 for a in A]
#print(A)

Acum = [0] + list(accumulate(A))
answer = -1
for i in range(N + 1 - K):
    answer = max(answer, Acum[i + K] - Acum[i])
    
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
t = [0] * N
for i in range(N):
  x = a[i]
  t[i] = (x + 1) / 2
s = sum(t[: K])
res = s + 0
for i in range(N - K):
  s -= t[i]
  s += t[i + K]
  res = max(res, s)
print(res)

Submission status: Accepted

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

import itertools
pl_ac = [0] + list(itertools.accumulate(pl))

ans = 0
for i in range(n-k+1):
    tmp = pl_ac[i+k] - pl_ac[i]
    ans = max(tmp, ans)
print((ans+k)/2)

Submission status: Accepted

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

N, K = map(int, readline().split())
P = list(map(int, readline().split()))
AP = P[:]
for i in range(1, N):
    AP[i] += AP[i-1]
AP = [0] + AP
ans = 0
for st in range(N-K+1):
    en = st+K
    ans = max(ans, AP[en] - AP[st])

print((ans+K)/2)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, p: "List[int]"):
    q = [(1 + v) / 2 for v in p]
    ret = 0
    s = sum(q[:K])
    l = 0
    for i in range(0, N - K):
        tmp = s - l
        ret = max(ret, tmp)
        l += q[i]
        s += q[i + K]
    ret = max(ret, s - l)
    print(ret)
    return

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: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline

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

    A = [(1+p)/2 for p in P]
    A_cs = [0] * (N+1)
    for i in range(N):
        A_cs[i+1] = A_cs[i] + A[i]
    ans = 0
    for i in range(N-K+1):
        ans = max(ans, A_cs[i+K] - A_cs[i])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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

Es = [p*(p+1)/2/p for p in ps]

accEs = list(accumulate([0]+Es))

ans = 0
for i in range(N-K+1):
    e = accEs[i+K] - accEs[i]
    ans = max(ans, e)

print(ans)

Submission status: Accepted

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

N, K = MAP()
p = LIST()

l = 0
r = K
ma = 0
tmp = sum(p[:K])
ma = tmp
for i in range(N-K):
	tmp = tmp - p[i] + p[i+K]
	if tmp > ma:
		ma = tmp
		l = i+1
		r = i+K+1
# print(l, r)

ans = 0

for i in range(l, r):
	ans += (p[i]+1)/2
print(ans)

Submission status: Accepted

Solution code:
def examA():
    S, T = LSI()
    A, B = LI()
    U = SI()
    if S==U:
        print(A-1,B)
    else:
        print(A,B-1)
    return

def examB():
    S = SI()
    N = len(S)
    ans = ""
    for i in range(N):
        ans += "x"
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
        if d[a]>=2:
            print("NO")
            return
    print("YES")
    return

def examD():
    N, K = LI()
    P = LI()
    S = [0]*(N+1)
    for i in range(N):
        S[i+1] = S[i]+(P[i]+1)/2
    ans = 0
    for i in range(N-K+1):
        cur = S[i+K]-S[i]
        ans = max(ans,cur)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
P=list(map(int,input().split()))

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

#print(P)

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
p = list(map(int, input().split()))
p = [(i+1)/2 for i in p]
cs = [0]
for i in p:
    cs.append(cs[-1]+i)
ma = 0
for i in range(n-k+1):
    if ma < cs[i+k]-cs[i]:
        ma = cs[i+k]-cs[i]

print(ma)