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:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n, k = na()
p = na()
d = [0] * (n + 1)
for i in range(n):
    a = (p[i] * (p[i] + 1) // 2) * (1 / p[i])
    d[i + 1] = d[i] + a

ans = 0.0
for i in range(n - k + 1):
    a = d[i + k] - d[i]
    ans = max(ans, a)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.signal import fftconvolve

n, k = map(int, input().split())
P = np.array(input().split(), dtype=int)
template = np.ones(k)

a = fftconvolve(P, template, mode="valid")

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

Submission status: Accepted

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

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

    pionta = None
    ire = [None for i in range(k)]
    d = {}
    d[0] = 0

    ss = 0
    for i in range(0, n):
        if k < i + 1:
            pionta = i % k
        if pionta is None:
            ire[i] = p[i]
        else:
            ss += p[i] - ire[pionta]
            d[ss] = i
            ire[pionta] = p[i]


    max_s = max(d.keys())
    i = d[max_s]
    m = 0
    for i2 in range(i-k+1, i+1):
        m += K(p[i2])
    return m
print(d())

Submission status: Accepted

Solution code:

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

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

expt=list(map(expct,p))

maxval=sum(expt[0:k])
curval = maxval

for i in range(1,n-k+1):
  curval -= expt[i-1]
  curval += expt[k+i-1]
#  print(maxval,curval)
  if curval>maxval:
    maxval=curval

print(maxval)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=[int(i) for i in input().split()]
q=[(i+1)/2 for i in p]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+q[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:
# -*- coding: utf-8 -*-

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

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

ans = 0
for i in range(N - K + 1):
    if ans < l[i + K] - l[i]:
        ans = l[i + K] - l[i]

print(ans)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
p = [(int(i) + 1) * 0.5 for i in 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('{:.7f}'.format(m))

Submission status: Accepted

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

max_val = 0
max_idx = 0
tmp = 0
for i in range(1,N-K+2):
  if i == 1:
    tmp = sum(p[i-1:i-1+K])
  else:
    tmp = tmp - p[i-2] + p[i-2+K]
  if tmp > max_val:
    max_val = tmp
    max_idx = i

p = p[max_idx-1:max_idx-1+K]
p.sort()
prev_tmp = 0.0
expect = 0.0
for i in range(len(p)):
  tmp = 0.0
  if i == 0:
    for j in range(1,p[i]+1):
      tmp += j
    expect += tmp/p[i]
    prev_tmp = tmp
  else:
    tmp = prev_tmp
    for j in range(p[i-1]+1,p[i]+1):
      tmp += j
    expect += tmp/p[i]
    prev_tmp = tmp
print(expect)

Submission status: Accepted

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

s = sum(p[:K]) 
m = s

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

print((m+K)/2)

Submission status: Accepted

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

import math
from collections import deque

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

def expected(x):
    s = 0
    if x % 2 == 1:
        s = x * math.ceil(x / 2)
    else:
        s = (x + 1) * (x / 2)

    return s / x

b = {}
mx = 0
# 前回分
q = deque()
p = 0

for i in range(N - K + 1):
    s = 0
    # 初回は全部計算
    if i == 0:
        for j in range(K):
            k = i + j
            if not P[k] in b:
                b[P[k]] = expected(P[k])
            s += b[P[k]]
            # 順番に保持
            q.append(b[P[k]])
    else:
        # 追加分
        k = i + (K - 1)
        if not P[k] in b:
            b[P[k]] = expected(P[k])
        # シフト
        f = q.popleft()
        q.append(b[P[k]])

        # 計算
        s = p - f + b[P[k]]

    # 最大更新
    mx = max(mx, s)
    # 前回分として保持
    p = s

print(mx)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

    def calc(p):
        if p % 2 == 0:
            return p/2 + 0.5
        else:
            return math.ceil(p/2)

    E = [calc(pi) for pi in P]
    #print(E)

    best_idx = 0
    best_sum = 0

    cs = np.cumsum(E)
    cs = np.insert(cs, 0, 0)
    #print(cs)

    for i in range(K-1, N):
        #print(i)
        s = cs[i+1] - cs[i-K+1]
        #print(s)
        if s > best_sum:
            best_sum = s
            best_idx = i

    print(best_sum)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

ans = 0
for e in q[0:k]:
  ans += e
anses = [ans]

for i in range(n - k):
  ans -= q[i]
  ans += q[k + i]
  anses.append(ans)

print(max(anses))

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    P = [(v + 1) / 2 for v in map(int, input().split())]

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    cur = sum(p[0:K])
    max = cur
    for i in range(N - K):
        cur = cur - p[i] + p[i + K]
        if cur > max:
            max = cur

    print((max + K) / 2)


main()

Submission status: Accepted

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


kitaiti = {}

k = 1.0
for i in range(1, 1001):
    kitaiti[i] = k
    k += 0.5

index = 0

for i in range(K):
    index += kitaiti[P[i]]

s = index
ans = index

for i in range(1, len(P)-K+1):
    s = index - kitaiti[P[i-1]] + kitaiti[P[i+K-1]]
    if s > ans: ans = s
    index = s
print(ans)

Submission status: Accepted

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

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

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

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

import copy
from collections import deque
# 対象特定
ans_start = 0
dices_sum = 0
tmp_dices = None
for start in range(0, N-K+1):
    if tmp_dices == None:
        tmp_dices = deque(P[start:start+K])
        tmp_sum = sum(tmp_dices)
    else:
        removed = tmp_dices.popleft()
        tmp_dices.append(P[start+K-1])
        tmp_sum = tmp_sum - removed + P[start+K-1]
    if tmp_sum > dices_sum:
        ans_start = start
        dices_sum = tmp_sum

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

Submission status: Accepted

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

dp = [0] * n
for i in range(n):
  dp[i] = p[i] / 2 + 0.5
  
m = sum(dp[0:k])
max = m
for i in range(1,n-k + 1):
  m = m - dp[i-1] + dp[i+k-1]
  if m > max:
    max = m
print(max)

Submission status: Accepted

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

wa = float(0)
for i in range(K):
    wa = wa + P[i]

ans = wa 
  
repeat = N-K
for i in range(repeat):
    wa = wa + P[i+K]-P[i]
    if ans <= wa :
        ans = wa
      
print(ans/2+(K*0.5))

Submission status: Accepted

Solution code:
N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])
    now_sum = max_sum
  else:
    now_sum += (p_list[i-1+K] - p_list[i-1])
    if max_sum < now_sum:
      max_sum = now_sum

print((max_sum + K)/2)

Submission status: Accepted

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


def cal_expect(value):
    return ((value*(value+1))/2)*(1/value)

expect_value = [0]*N
expect_value[0] = cal_expect(p[0])

for i in range(1,K):
    expect_value[i] += expect_value[i-1] + cal_expect(p[i])

for i in range(K,N):
    expect_value[i] = expect_value[i-1] + cal_expect(p[i]) - cal_expect(p[i - K])

print(max(expect_value))

Submission status: Accepted

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

Submission status: Accepted

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

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

maxval = 0

temp = -1

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

for i in range(n-(k-1)):
	# print(i, k)
	summ = 0
	if temp == -1:
		for j in range (k):
			summ += expectedval(plist[i + j])
		temp = summ
	else:
		# print(plist[i-1], plist[i+k -1], expectedval(plist[i - 1]), expectedval(plist[i + k - 1]))
		summ = temp - expectedval(plist[i - 1]) + expectedval(plist[i + k - 1])
		temp = summ
	# print(summ)
	maxval = max(summ, maxval)

print(maxval)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

#素因数分解
def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

#重複を検出
def has_duplicates(seq):
  return len(seq) != len(set(seq))



#X = str(input()).split()
#a = [int(x) for x in input().split()]


NK = str(input()).split()
N = int(NK[0])
K = int(NK[1])
p = [int(x) for x in input().split()]

M = 0
ans = 0

for i in range(K):
  M+= p[i]

ans = M
ans2 = 0
ans3 = 0
ans4 = 0

for i in range(K, N):
  M = M-p[i-K]+p[i]
  if(ans < M):
    ans2 = i-K+1
    ans = M

for i in range(ans2,ans2+K):
  for j in range(p[i]+1):
    ans3 += j
    #print(ans3)
  ans4 += float(ans3/p[i])
  ans3 = 0


print(ans4)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import itertools
import time

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

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

kukan_max = kukan
for i in range(n - k + 1):
    kukan_max = max(kukan_max, kukan)
    if i+k<n:
        kukan += p[i+k]
        kukan -= p[i]
ans = kukan_max / 2 + 0.5 * k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

st = list(accumulate(range(1001)))
#print(st)
table = [0] * (n + 1)
for i in range(1, len(table)):
    table[i] = table[i-1] + (st[p[i-1]] / p[i-1])
    #print(i, p[i-1], st[p[i-1]], table[i])
    
ans = table[k]
for i in range(k+1, len(table)):
    ans = max(ans, table[i] - table[i-k])

print(ans)

Submission status: Accepted

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

for i in range(len(p)):
    p[i]=(p[i]+1)/2
tmp=sum(p[0:k])
x=sum(p[0:k])
for i in range(k,len(p)):
    x=x-p[i-k]+p[i]
    if x>tmp:
        tmp=x
print(tmp)

Submission status: Accepted

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

n, k = map(int, input().split())
p = np.array(input().split(), dtype='int')

max_E = 0

e = (p - 1) * 0.5 + 1

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

for i in range(n - k + 1):
    if i == 0:
        E = first_E
    else:
        E = E - e[i - 1] + e[i + k - 1]
    
    if E > max_E:
        max_E = E

print(max_E)

Submission status: Accepted

Solution code:

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


s = sum(p[0:K])
s_max = s

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

    if s_max < s:
        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()))

#累積和を前計算
sum_list = [0 for _ in range(300000)]
sum = 0

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

#答えを計算
mev = 0
idx = 0
for i in range(N-K+1):
    ev = sum_list[i+K]-sum_list[i]
    if ev > mev:
        idx = i
        mev = ev

mev = 0.0
if N != K:
    for i in range(idx+1,idx+1+K):
        mev += (p[i] + 1.0) / 2.0

else:
    for i in range(len(p)):
        mev += (p[i] + 1.0) / 2.0

print(mev)

Submission status: Accepted

Solution code:
def solve():
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))
    curSum = sum(ps[:K])
    curMax = curSum
    i = K; j = 0
    while i < N:
        curSum -= ps[j]
        curSum += ps[i]
        curMax = max(curSum, curMax)
        i += 1; j += 1
    print((curMax + K) / 2)
solve()

Submission status: Accepted

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

number_list = []

sum_max = 0
tmp_max = 0
past_max = 0
tmp_max_list = []
for index, p in enumerate(p_list):
    if index >= K:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max -= tmp_max_list[index - K]
        if sum_max < tmp_max:
            sum_max = tmp_max
        tmp_max_list.append((p * (p + 1)) / 2 / p)
    else:
        tmp_max += (p * (p + 1)) / 2 / p
        tmp_max_list.append((p * (p + 1)) / 2 / p)

if N == 1:
    print('{:.12f}'.format(float(p_list[0] * (p_list[0] + 1) / 2 / p_list[0])))
elif N == K:
    print('{:.12f}'.format(float(sum(tmp_max_list))))
else:
    print('{:.12f}'.format(float(sum_max)))

Submission status: Accepted

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

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

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

ans = 0
a =0

for i in range(len(p)):
    #a = list(range(1,p[i]+1))
    #print(a)
    p[i] = ((p[i]*(p[i]+1))/2)/p[i]
    a += p[i]
    
    if i >= K-1:
        
        if i >= K:
            a += -(p[i-K])
        if a > ans:
            ans = a

print(ans)

Submission status: Accepted

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

n, k = map(int, input().split())
P = [int(i) for i in input().split()]

if k == 1:
    m = max(P)
    print((m+1)/2)

else:
    Pa = [(1+h)/2 for h in P]
    if n == k:
        print(sum(Pa))
    else:
        sm = sum(Pa[:k])
        r_ind = k-1
        r_res = k-1
        l_ind = 0
        l_res = 0
        s = sm
        while r_ind < n - 1:
            right = Pa[r_ind + 1]
            left = Pa[l_ind]
            s += right
            s -= left
            if sm < s:
                sm = s
                l_res = l_ind
                r_res = r_ind
            r_ind += 1
            l_ind += 1

        m = 0
        for f in Pa[l_res+1:r_res+2]:
            m += f

        print(m)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

p = list(map(int,input().split()))
max = 0
for i in range(K):
    max += (1+p[i])/2
tmp = max
for i in range(K,len(p)):
    tmp -= (1+p[i-K])/2
    tmp += (1+p[i])/2
    #print(max)
    if max < tmp:
        max = tmp
    #print(max)    
print(max)




#ロケットペンシル方式

Submission status: Accepted

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

ans = 0
tmp,ind = sum(p[0:k]),0
sumn = tmp

for i in range(len(p)-k):
    #print(p[i+k],p[i])
    tmp += p[i+k]-p[i]
    #print(tmp)
    if tmp >= sumn:
        ind,sumn = i,tmp
        #print(sumn)

print((sumn+k)/2)
"""
for i in p[ind:ind+k]:
    ans += (i+1)/2
else:
    print(ans)
"""

Submission status: Accepted

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

Submission status: Accepted

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

mysum = [0] * 1001
for i in range(1, 1001):
    mysum[i] = mysum[i-1] + i

pp = list(map(lambda x: mysum[x] / x, p))

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

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
arr = list(map(int, input().split()))
kitai = 0
biglist = []
if k ==1:
    kitai = (max(arr)+1)/2
    print(kitai)
else:
    for i in range(n-k+1):
        if i == 0:
            big = 0
            for j in range(i+k):
                big = big + arr[j]
        else:
            big = biglist[i-1] - arr[i-1] + arr[i+k-1]
        biglist.append(big)
    max_value = max(biglist)
    max_index = biglist.index(max_value)
    for j in range(max_index,max_index+k):
        kitai = kitai + (arr[j]+1)/2
    print(kitai)

Submission status: Accepted

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

def exp(n):
    if n % 2 == 0:
        s = (n+1)*n/2
    else:
        s = (n+1)*(n-1)/2+(n+1)/2
    ans = s / n
    return ans

q = []
for i in range(N):
    q.append(exp(p[i]))
#print(q)

S = sum([q[i] for i in range(K)])
M = S
#print(M)

for i in range(N-K):
    S = S - q[i] + q[K+i]
    #print(S)
    if S > M:
        M = S

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

Submission status: Accepted

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

Submission status: Accepted

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

#def f(x):
#    if x == 1:
#        return 1
#    else:
#        return f(x-1) + x

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

max_index = 0
now_sum = sum(P[:K])
max_sum = now_sum
for i in range(1, len(P)-(K-1)):
    now_sum -= P[i-1]
    now_sum += P[i+K-1]
    #sum_P = sum(P[i:i+K])
    if now_sum > max_sum:
        max_sum = now_sum
        max_index = i

#print(max_sum)
#print(max_index)

# 隣接したK個のリスト
kk = P[max_index:max_index+K]

# kの期待値を計算
max_kk = max(kk)
dp = [0]
for i in range(1, max_kk+1):
    dp.append(dp[i-1] + i)
#print(dp)

ans = 0
for k in kk:
    ans += dp[k]/k

print(ans)

Submission status: Accepted

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

n,k = map(int,input().split())
p = list(map(int,input().split()))
a2=[0]
Max = 0
for i in p:a2.append(a2[-1]+i)
lists = []
for i in range(n-k+1):
    lists.append(a2[i+k] - a2[i])
jud = max(lists)
for i in range(len(lists)):
    if lists[i] == jud:
        tmp = i
ans = p[tmp:tmp+k]
cnt = 0
for i in ans:
    cnt += mysum(i)
print(cnt)

Submission status: Accepted

Solution code:
[N,K] = [int(s) for s in input().rstrip().split(' ')]
L_A = [int(s) for s in input().rstrip().split(' ')]
if N < K:
  print("error")
elif N == K:
  print((sum(L_A) + N) / 2)
else:
  a = N - K
  p = 0
  for i in range(K):
    p += L_A[i]
  q = p
  for j in range(N-K):
    q += L_A[j+K]-L_A[j]
    p = max(p,q)
  print((p + K) / 2)

Submission status: Accepted

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

#累積和を出す
t = [0] * (len(p) + 1)
for i in range(len(p)):
  t[i + 1] = t[i] + p[i]

#連続するK個の和で、最大の値を取得する。
maximum = -1
start = -1

for i in range(len(p) - k + 1):
  temp = t[i + k] - t[i]
  if temp > maximum:
    maximum = temp
    start = i

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

print(exp)

Submission status: Accepted

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



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

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

Submission status: Accepted

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

p = [int(e) for e in input().split()]

now_sum = sum(p[0:K])
now_max = copy(now_sum)


for i in range(K,N):
    now_sum = now_sum - p[i - K] + p[i]
    if now_sum > now_max:
        now_max = copy(now_sum)

print((K + now_max)/2)

Submission status: Accepted

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

maxSum = 0
sum = 0
prevSum = 0

for i in range(K):
  maxSum += p[i]

prevSum = maxSum;
for i in range(N - K):
  sum = prevSum - p[i] + p [i + K]
  if maxSum < sum:
    maxSum = sum
  prevSum = sum

ans = (maxSum + K) / 2.0
print('{:.7f}'.format(ans))

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

ans = 0
cur = 0
for i in xrange(k):
  cur += a[i]

ans = max(ans, cur)
for i in xrange(k, n):
  cur -= a[i - k]
  cur += a[i]
  
  ans = max(ans, cur)

ans = ans + k
ans /= 2.0

print "{0:.9f}".format(ans)

Submission status: Accepted

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

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


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

Submission status: Accepted

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

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


fs = p[:k]
f = sum(fs)
m = n - k + 1
qs = np.zeros(m)
qs[0] = f
if n == k:
    ans = (f + k)/2
    print(ans)
else:
    for i in range(k,n):
        a = qs[i-k] - p[i-k] + p[i]
        qs[i-k+1] = a
    ans = (max(qs)+k) / 2
    print(ans)

Submission status: Accepted

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

def kitaiti(n):
    return 0.5*n + 0.5

ans = 0

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

for i in range(N-K+1):
    val = s[K+i] - s[i]
    if ans<val:
        ans = val

print(kitaiti(ans)+0.5*(K-1))

Submission status: Accepted

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

n, k = [int(i) for i in input().split()]
p = [0] * n
for i,v in enumerate(input().split()):
    p[i] = 1.0 + 0.5 * (float(v) - 1.0)

_max_sum = 0
_prev_sum = 0
for i in range(0, n-k+1):
    if i == 0:
        _sum = sum(p[:k])
    else:
        _sum = _prev_sum - p[i-1] + p[i+k-1]
    if _sum >= _max_sum:
        _max_sum = _sum
    _prev_sum = _sum
print(_max_sum)

Submission status: Accepted

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

Submission status: Accepted

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

rp = sum(list(p[0:K]))
rm = 0
ans = rp
for i in range(N-K):
  rp += p[i+K]
  rm += p[i]
  if rp - rm > ans:
    ans = rp - rm

print((ans+K)/2)

Submission status: Accepted

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

kitaiti = [0 for _ in range(n)]
ruisekiwa = [0 for _ in range(n)]
r = k - 1
max = 0
now = 0
ans_list = []

for i in range(n):
    kitaiti[i] = (p[i]+1) / 2
    if i == 0:
        ruisekiwa[0] = kitaiti[0]
    else:
        ruisekiwa[i] = ruisekiwa[i-1] + kitaiti[i]
    if i == r:
        now = ruisekiwa[i]
    elif i > r:
        now = ruisekiwa[i] - ruisekiwa[i-r-1]
    if now > max:
        max = now
print(max)

Submission status: Accepted

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

a = []
for e in p:
    a.append((1+e)/2.0)

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

res = []
res.append(tmp)
for i in range(k,n):
    tmp += a[i] - a[i-k]
    res.append(tmp)

print(max(res))

Submission status: Accepted

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

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
max_ans = ans
max_index = 0

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    if max_ans < ans:
        max_ans = ans
        max_index = i+1

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
fac = [0] * 735477
fac[0] = 1
if (N >= 1):
    for i in range(1, 1010): fac[i] = i + 1 + fac[i - 1]
# 期待値
#print(p, fac[:max(p)])
exp = [0] * 735477
for i in range(N):
    exp[i] = fac[p[i] - 1] / p[i]
# print(exp)

Ans = 0
ans = [0] * 735477
ans[0] = sum(exp[:K])
for i in range(1, N - K + 1):
    if(i + K == N + 1): break
    ans[i] = ans[i - 1] - exp[i - 1] + exp[i + K - 1]
    # print(ans[i])
    #print(exp[i: i + K])
print(max(ans))

Submission status: Accepted

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

if K==1:
    print((max(p)+1)/2)
    exit()

contents_origin=sum(p[:K])
contents=sum(p[:K])
pK = p[:K]

for idx, i in enumerate(p[:-K]):
    contents=contents-p[idx]+p[idx+K]
    contents_origin=max(contents_origin,contents)
print((contents_origin+K)/2)

Submission status: Accepted

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

sum = 0
for k in range(K):
  sum += p_list[k]
max = sum

i = 0
while(i + K  < N):
  sum = sum - p_list[i] + p_list[i+K]
  if(sum > max):
    max = sum
  i += 1

print(0.5 * (max+K))

Submission status: Accepted

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

mini = 0
kitai = 0
sum1 = []
p2 = []
ans = 0
base = 0
sei = 0
a = 0
d = {}
for i in range(max(p) + 1):
    a += i + 1
    sum1.append(a)

for i in range(k):
    p3 = sum1[p[i] - 1] / (p[i])
    p2.append(p3)
    base += p3


ans = base


for i in range(1, n):
    if i + k - 1 >= n:
        break
    else:
        p3 = sum1[p[i + k - 1] - 1] / (p[i + k - 1])
        p2.append(p3)
        base = base - p2[i - 1] + p3
        if ans < base:
            ans = base

print(ans)

Submission status: Accepted

Solution code:
#python3

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

def main():
    n, k = map(int, input().split())
    fp = [f(int(i)) for i in input().split()]
    n = len(fp)
    v = sum(fp[0:k])
    i = 0
    ans = v
    while i+k <= n-1:
        v = v-fp[i]+fp[i+k] 
        ans = max(ans, v)
        i+=1

    a = "{0:.12f}".format(ans)
    print(a)

main()

Submission status: Accepted

Solution code:
from collections import deque

n, k = map(int, input().split())
ps = list(map(int, input().split()))
ps = [(p + 1)/2 for p in ps]
# print(ps)

d = deque()
vmax = 0
v = 0
for p in ps:

    if len(d) == k:
        old = d.popleft()
        new = p
        d.append(new)
        v = v + new - old
        if v > vmax:
            # print("v > vmax")
            vmax = v
    else:
        d.append(p)
        v += p
        vmax = v
    # print(vmax, v, d)

print(vmax)