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:

nk = list(map(int, input().split()))
p = list(map(int, input().split()))
s=0
summo=0
l = []
for i in range(1,1001):
    s += i
    l.append(s/i)

r = []
for i in range(nk[0]):
    summo += l[p[i]-1]
    r.append(summo)

ans = 0
for i in range(nk[0]):
    if i-nk[1] >= 0:
        if ans < r[i]-r[i-nk[1]]:
            ans = r[i]-r[i-nk[1]]
    else:
        if ans < r[i]:
            ans = r[i]
print(ans)

Submission status: Accepted

Solution code:
N, K = (int(i) for i in input().split())
p = [int(i) for i in input().split()]
p_ex = [(i+1)/2 for i in p]
sum_list = [sum(p_ex[0:K]),sum(p_ex[N-K:N])]
tmp_num = sum_list[0]
if N == K:
  print(sum(p_ex))
else:
  for i in range(1,N-K):
    #print("i:"+str(i))
    tmp_num = tmp_num - p_ex[i-1] + p_ex[i+K-1]
    #print("  tmp_num = tmp_num - "+str(p_ex[i-1])+" + "+str(p_ex[i+K-1]))
    sum_list.append(tmp_num)
  print(max(sum_list))

Submission status: Accepted

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

m = 0
pre = 0
for j in range(K):
    pre += l[j]
m = pre

if K>1 and N>K:
  for i in range(N-K):
    temp = pre
    temp += l[i+K]
    temp -= l[i]
    if temp > m:
      m = temp
    pre = temp

if K==1:
  for i in range(N):
    if l[i] > m:
      m = l[i]


print((m+K)/2)

Submission status: Accepted

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

def kitai(x):
    return (x+1)/2
nP=list(map(kitai,P))
l=[]
m=sum(nP[0:K])
l.append(m)
for i in range(N-K):
    m -= nP[i]
    m += nP[i+K]
    l.append(m)
print(max(l))

Submission status: Accepted

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

E = []
for p in P:
  E.append((p+1)*p/2/p)
csum = [0]
for i in range(N):
  csum.append(csum[-1]+E[i])
mx = 0
for i in range(N-K+1):
  mx = max(csum[K+i]-csum[i],mx)
print(mx)

Submission status: Accepted

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

expectedList = [(1 + s) /  2 for s in p]
cumsum = sum(expectedList[:K])
confirm_cumsum = cumsum

for i in range(K, N):
    cumsum += expectedList[i]
    cumsum -= expectedList[i - K]
    if cumsum > confirm_cumsum:
        confirm_cumsum = cumsum

print(confirm_cumsum)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
* P, = map(int, input().split())
P = [(1+p)/2 for p in P]
M1 = sum(P[:K])
M0 = M1
for i in range(K, N):
    M0 += P[i]
    M0 -= P[i - K]
    if M0 > M1:
        M1 = M0
print(M1)

Submission status: Accepted

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

ans = 0
for i in range(k):
    ans += ps[i]
tmp = ans
for i in range(k,n):
        tmp = tmp - ps[i-k] + ps[i]
        if ans < tmp:
            ans = tmp
    
print(ans)

Submission status: Accepted

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

for i in range(len(p)):
  p[i]+=1

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = [0] * 1000000
for i in range(n):
  s[i+1] = s[i] + a[i]
  
max_s = 0
for i in range(n):
  if max_s < s[i+k] - s[i]:
    max_s = s[i+k] - s[i]
print((max_s+k) / 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N,K = [int(x) for x in input().split()]
p =[0]+[int(x) for x in input().split()]
pa = list(accumulate(p))
an = 0
ans = 0
for i in range(N-K+1):
  if an<pa[i+K]-pa[i]:
    an = max(an,pa[i+K]-pa[i])
    ans = 0
    for l in range(K):
      ans += (p[l+i+1]+1)/2
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n, k = map(int, input().split())
p = (1.00 + np.array(list(int(i) for i in input().split()))) / 2
temp = np.sum(p[:k])
ans = temp

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

print('{:.10f}'.format(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n,k = map(int, input().split())
p = (1.00 + np.array(list(int(i) for i in input().split()))) / 2
temp = np.sum(p[:k])
ans = temp

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

print('{:.10f}'.format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

p.insert(0, 0)
for i in range(1, N+1):
    p[i] = (p[i] + 1) / 2 + p[i-1]

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

print(max(s))

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5 3
1 2 2 4 5
'''

def solve(l,k):
	n = len(l)
	pre = [l[0]]
	for i in range(1,n):
		pre.append(pre[i-1] + l[i])
	maxx = 0
	index = -1
	for i in range(k-1,n):
		summ = 0
		if(i == k-1):
			summ = pre[i]
		else:
			summ = pre[i] - pre[i-k]
		if(maxx < summ):
			maxx = summ
			index = i
	startIndex = index - k + 1
	optimalSub = l[startIndex:index+1]
	# print(optimalSub)
	ans = 0
	for i in optimalSub:
		curr = i*(i+1)/2
		ans += curr/i
	return ans

N,K = map(int, stdin.readline().rstrip().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,K)
print("%.10f"%ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[(i+1)/2 for i in a]
from itertools import accumulate
a=list(accumulate(a))
ans=0
for i in range(n-k+1):
    if i-1>=0:
        tmp=a[i+k-1]-a[i-1]
    else:
        tmp=a[i+k-1]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

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

S = []
count = 0
max_sum = 0
for p in P:
    e = (int(p) + 1) / 2
    if count == 0:
        S.append(e)
    else:
        S.append(S[count-1] + e)
    if count == (K - 1):
        max_sum = S[count]
    elif count > (K - 1):
        sum = S[count] - S[count - K]
        if max_sum < sum:
            max_sum = sum
    count += 1
print(max_sum)

Submission status: Accepted

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

dicesum = 0
maxsum = 0
for i in range(n):
	dicesum += p[i]
	if i >= k:
		if n != k: dicesum -= p[i-k]
	maxsum = max(maxsum, dicesum)

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

Submission status: Accepted

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

for i in range(len(p)):
	p[i] = .5 * (p[i] + 1)

tsum = sum(p[:k])
msum=tsum
for i in range(k, len(p)):
	tsum += p[i] - p[i-k]
	msum = max(msum, tsum)

print(msum)

Submission status: Accepted

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

Submission status: Accepted

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()
P = read_ints()


def ret_mean(X):
    return (X + 1) / 2



class cumsum1d:
    def __init__(self, ls: list):
        '''
        1次元リストを受け取る
        '''
        from itertools import accumulate
        self.ls_accum = [0] + list(accumulate(ls))

    def total(self, i, j):
        # もとの配列lsにおける[i,j)の中合計
        return self.ls_accum[j] - self.ls_accum[i]
      
P_mean = [ret_mean(p) for p in P]
P_accum = cumsum1d(P_mean)

ans = 0
# print(P_accum)
for i in range(N - K + 1):
    j = i + K
    ans = max(ans, P_accum.total(i,j))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    p = LI()
    t = 0
    for i in range(k):
        t += (p[i]+1) / 2
    r = t
    for i in range(k,n):
        t += (p[i]+1) / 2
        t -= (p[i-k]+1) / 2
        if r < t:
            r = t

    return r


print(main())

Submission status: Accepted

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

Submission status: Accepted

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()
P = read_ints()


def ret_mean(X):
    return (X + 1) / 2




import numpy as np
P_mean = np.array([ret_mean(p) for p in P])
P_accum = np.zeros(N+1)
P_accum[1:] = P_mean.cumsum()

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

Submission status: Accepted

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

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

c_sum = [0]
v_sum = 0
for p_j in p:
  v_sum += p_j
  c_sum.append(v_sum)

a_max = 0
for i in range(n-k+1):
  if a_max < (c_sum[i+k] - c_sum[i]):
    a_max = (c_sum[i+k] - c_sum[i])
  
print(a_max)

Submission status: Accepted

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

# 平均値のlist
m = [(e + 1) / 2 for e in p]

t = sum(m[0:K])
result = t

for i in range(N - K):
    t -= m[i]
    t += m[i + K]
    if t > result:
        result = t
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import queue

n, k = input().split()
p = input().split()
n = int(n)
k = int(k)
p = [int(p_tmp) for p_tmp in p]
q = queue.Queue()

wa = []
max = 0
sum = 0
for i in p:
    i += 1
    sum += i
    q.put(i)
    if q.qsize() > k:
        sum -= q.get()
    
    if q.qsize() == k:
        if max < sum:
            max = sum
        
ans = max
ans /= 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
buf=0
maxi=0
for i in range(k):
    buf+=p[i]
maxi=buf
for i in range(k,n):
    #print(buf)
    buf+=p[i]
    buf-=p[i-k]
    if maxi<buf:
        maxi=buf
print(maxi)

Submission status: Accepted

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

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

Submission status: Accepted

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

cum = [0]
for i in range(1, n+1):
    cum.append(cum[i-1] + (p[i-1]+1)/2)

res = 0
for i in range(0, n-k+1):
    val = cum[i+k] - cum[i]
    if res < val:
        res = val

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n, k = map(int, input().split())
p_array = np.array(list(map(int, input().split())))
expc = lambda x: (x+1.0)/2.0
p_array = expc(p_array)

p_cum = np.cumsum(p_array)
p_cum_diff = p_cum[k:] - p_cum[0:n-k]
if len(p_cum_diff) > 0:
    print(max(p_cum_diff))
else:
    print(p_cum[-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

wk = 0
nn = n-k

for i in range(0,k):
    wk += li[i]
kwk = wk
for j in range(nn):
    wk = wk - li[j]
    wk = wk + li[j+k]
    kwk = max(wk,kwk)
 
print(kwk)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
expects = [0.0]
for i in range(1, 1001):
    p = 0.0
    for j in range(i, 0, -1):
        p += j * 1.0 / i
    expects.append(p)
exp_P = [0.0]
for i in range(N):
    exp_P.append(exp_P[-1] + expects[P[i]])

# print(exp_P)
ans = float('-inf')
for i in range(K, N+1):
    ans = max(ans, exp_P[i] - exp_P[i-K])
print(ans)

Submission status: Accepted

Solution code:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n, k = [int(v) for v in input().split()]
p = [int(v) for v in input().split()]

max_p = max(p)

dp = [0] * (max_p+1)
dp[1] = 1
for i in range(2, max_p+1):
    dp[i] = dp[i - 1] + i
    dp[i - 1] /= (i - 1)
dp[max_p] /= max_p

e = 0
for i in range(k):
    e += dp[p[i]]

max_e = e

for i in range(k, n):
    e -= dp[p[i - k]]
    e += dp[p[i]]
    max_e = max(max_e, e)

print(max_e)

Submission status: Accepted

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

L = 0
R = k

def expected(pi):
    return (pi+1)/2

value = 0.0
sans  = 0.0
for i in range(0, k):
    sans += expected(p[i])
ans   = sans

while R < n:
    sans -= expected(p[L])
    sans += expected(p[R])

    ans = max(ans, sans)

    L += 1
    R += 1
print("%.7f" % ans)

Submission status: Accepted

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

e=0
for i in range(idx,idx+k):
    e+=((p[i]+1)/2)
print(e)

Submission status: Accepted

Solution code:
import queue

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

q = queue.Queue()

#arr = [(n+1)/2 for n in P]
mx = 0
s = 0

for i in range(N):
  s += P[i]+1
  q.put(P[i]+1)
  if q.qsize() > K:
    s -= q.get()
  if q.qsize() == K:
    mx = max(mx, s)

ans = mx/2
print(ans)

Submission status: Accepted

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

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

# 累積和初期化
s_list = [0] * (N + 1)

for i in range(N):
	s_list[i + 1] = s_list[i] + p_list[i]

# 隣り合うK個の要素の和が最大になるような範囲の開始位置を求める
max_s_sum = 0
max_sum_index = 0

for n in range(N - K + 1):
    s_sum = s_list[n + K] - s_list[n]
    if max_s_sum < s_sum:
        max_s_sum = s_sum
        max_sum_index = n

# 求めた開始位置から隣接するK個の要素の期待値を求める
ans = 0
for k in range(K):
    x = p_list[max_sum_index]
    ans += (x + 1) / 2
    max_sum_index += 1
  
print(ans)

Submission status: Accepted

Solution code:
def main():
	n,m = map(int,input().split())
	a = list(map(int,input().split()))
	wa = [0,(1/2 * a[0] * (a[0] +1))/a[0]]
	for i in range(1,n):
		wa.append(wa[i] + (1/2 * a[i] * (a[i]+1))/a[i])
	ans = wa[m-1]
	for i in range(m,len(wa)):
		ans = max(wa[i]-wa[i-m],ans)
	print(ans)
	
 
if __name__ == '__main__':
	main()

Submission status: Accepted

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

lis = [(ele+1)/2 for i, ele in enumerate(lis)]

ans_lis = []

ans_lis.append(sum(lis[0:K]))

for i in range(N-K):
    ele = ans_lis[-1] - lis[i] + lis[i+K]
    ans_lis.append(ele)
    
print(max(ans_lis))

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
R = sum(P[:K])
ans = R
for j in range(N-K):
  R = R - P[j] + P[j+K]
  ans = max(ans,R)
print(ans)

Submission status: Accepted

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

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

m = max(P)
print((m+k)/2)

Submission status: Accepted

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

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

ans = L

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n, k = map(int, inputs[0].split())
P = list(map(int, inputs[1].split()))
EP = [0.5*p + 0.5 for p in P]

buffer = sum(EP[:k])
Q = [buffer]
for i in range(k, n):
    buffer += EP[i] - EP[i-k]
    Q.append(buffer)
print(max(Q))

Submission status: Accepted

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

e = [(x + 1) / 2 for x in p]
s = sum(e[:k])
maxsum = s
for i in range(n - k):
    s = s - e[i] + e[k + i]
    maxsum = max(maxsum, s)

print(maxsum)

Submission status: Accepted

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

c=[(i+1)/2 for i in p]
d =sum(c[:K])
e =d
for i in range(N-K):
    e -= c[i]
    e += c[i+K]
    if e>d:
        d=e
print(d)

Submission status: Accepted

Solution code:
import numpy as np

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

max = 0
sum = 0
for i in range(N):
    sum += P[i]
    if i >= K:
        sum -= P[i-K]
    if max < sum:
        max = sum
print((max+K)/2)

Submission status: Accepted

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

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

a = 0

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

ans = a

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

ans = (ans+k)/2

print(ans)

Submission status: Accepted

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

sum_=0
for i in range(k):
  sum_+=li[i]
max_=sum_

for i in range(k,len(li)):
  sum_-=li[i-k]
  sum_+=li[i]
  if max_<sum_:
    max_=sum_
max_+=k
max_/=2
print(max_)

Submission status: Accepted

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

Submission status: Accepted

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

pe = [1] * max(p)
for i in range(1, len(pe)):
    pe[i] += (pe[i-1] + i)

for i in range(1, len(pe)):
    pe[i] *= 1/(i+1)

ans = sum([pe[pi-1] for pi in p[0:k]])
s = ans
for i, t in enumerate(range(k, n)):
    s = s + pe[p[t]-1] - pe[p[i]-1]
    ans = max(ans, s)

print(ans)

Submission status: Accepted

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

kdice = [(1+p[i])/2 for i in range(n)]
maxexp = sum(kdice[:k])
ans = maxexp

for i in range(k, n):
    maxexp += kdice[i] - kdice[i-k]
    ans = max(maxexp, ans)

print(ans)

Submission status: Accepted

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

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

e = M
for i in range(n-k):
    e -= (1 + p[i]) / 2
    e += (1 + p[i+k]) / 2
    if e > M:
        M = e
print('{:.12f}'.format(M))

Submission status: Accepted

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

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)

Submission status: Accepted

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


def mean(value):
    return 0.5 * (value + 1)


res = 0
for l in range(k):
    res += mean(p[l])

cur = res
for l in range(k, n):
    cur += mean(p[l]) - mean(p[l-k])
    res = max(res, cur)
print(res)

Submission status: Accepted

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


def expectation(value):
    return 0.5 * (value + 1)


res = 0
for l in range(k):
    res += expectation(p[l])

cur = res
for l in range(k, n):
    cur += expectation(p[l]) - expectation(p[l-k])
    res = max(res, cur)
print(res)

Submission status: Accepted

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

sumex = sum(ex[:k])
tmp = sum(ex[:k])
for i in range(n-k):
    tmp = tmp + (ex[i+k] - ex[i])
    sumex = max(sumex, tmp)
print(sumex)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

exp={}
cum=[]

ans=0
cnt=0
for i in range(1,1001):
    sum=0
    for j in range(1,i+1):
        sum+=j
    exp[i]=sum/i

for i in p:
    cum.append(exp[i])

cumsum=list(accumulate(cum))
cumsum.insert(0,0)

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

print(ans)

Submission status: Accepted

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

m = [(e + 1) / 2 for e in p]
for i in range(1, N):
    m[i] += m[i - 1]

result = m[K - 1]
for i in range(N - K):
    t = m[K + i] - m[i]
    if t > result:
        result = t
print(result)

Submission status: Accepted

Solution code:
#ABC154D
import sys
N, K = map(int, sys.stdin.readline().split())
P = list(map(int, sys.stdin.readline().split()))

#print(P)

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2
#print(L)

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

#print(S)
total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)

Submission status: Accepted

Solution code:
def get(text,n):
    ans = [""]*n
    i = 0
    for x in text:
        if x==" ":
            i = i + 1
        ans[i] = ans[i]+x
    return ans

nk = input()
textp = input()

N = int(get(nk,2)[0])
K = int(get(nk,2)[1])
ps = get(textp,N)
for i in range(N):
    ps[i] = int(ps[i])

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

s = 0
for j in range(K):
    s = s + exp[j]
m = s
for i in range(N-K):
    s = s - exp[i] + exp[i+K]
    if m < s:
        m = s

print(m)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input().split()
N = int(n[0])
K = int(n[1])
a = input().split()
sum = 0.0
max = 0.0
for j in range(0, N):
  sum += float(a[j])
  if j > K - 1:
    sum -= float(a[j - K])
  if max < sum:
    max = sum
print ((max + K) / 2)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
expect_list = np.array(p_list)
expect_list = (expect_list + 1)/2
sum_list = []
#print(expect_list)
sum=0
for i in range(K):
    sum += expect_list[i]

sum_list.append(sum)

for i in range(1,N-K+1):
    sum -= expect_list[i-1]
    sum += expect_list[i+K-1]
    sum_list.append(sum)

print(max(sum_list))

Submission status: Accepted

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

s = 0
sums = [0]
for i in p:
  	s += i
  	sums.append(s)

maxNum = -1
maxIndex = [0, 0]
for i in range(len(sums)-k):
  if sums[i+k] - sums[i] > maxNum:
    maxNum = sums[i+k] - sums[i]
    maxIndex = [i, i+k-1]

dices = p[maxIndex[0]:maxIndex[1]+1]
e = 0
for dice in dices:
  e += sum(list(range(1, dice+1))) / dice
print(e)

Submission status: Accepted

Solution code:
N=2*10**5+7
n,k=map(int,input().split())
List=list(map(float,input().split()))
for i in range(n):
    List[i]=(1+List[i])/2
for i in range(1,n):
    List[i]+=List[i-1]
ans=0.0
for i in range(0,n-k+1):
    #ans=max(ans,List[i+k-1]-List[max(0,i-1)])
    if i==0 :
        ans=max(ans,List[i+k-1])
    else :
        ans=max(ans,List[i+k-1]-List[i-1])
print("{:.12f}".format(ans))

Submission status: Accepted

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

acc = []
x = 0
for i in range(n):
    x += p[i]
    acc.append(x)

ex = 0
for i in range(n-K+1):
    if i == 0:
        bre = acc[i+K-1]
    else:
        bre = acc[i+K-1] - acc[i-1]
    exx = (K+bre)/2
    
    if exx > ex:
        ex = exx
print(ex)

Submission status: Accepted

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

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)
else:
    m = prr[0]

print((m+k)/2.0)

Submission status: Accepted

Solution code:
def sin(): return input()
def ssin(): return input().split()
def nin(): return int(input())
def lin(): return list(map(int, ssin()))

N, K = lin()
p = [n*(n+1)/2/n for n in lin()]    

t = sum(p[:K])    
ans = t
l, r = 0, K-1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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