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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, k  = MAP()
p = LIST()

def kitai(a):
    tmp = 0
    # for a in A:
    tmp = 1/a * (1/2 * a * (a+1))
    return tmp
acc = [0] * n

# それぞれの期待値を先に求めて，それから和を求める
for i in range(n):
    acc[i] = (p[i] + 1) / 2
ruiseki = [0] * n
ruiseki[0] = acc[0]
for i in range(n-1):
    ruiseki[i+1] = ruiseki[i] + acc[i+1]
ruiseki.insert(0, 0)
# print(ruiseki)

ans = 0
for i in range(n-k+1):
    m = ruiseki[k+i] - ruiseki[i]
    # print(m)
    ans = max(ans, m)
print(ans)

    
    # if i == 0:
    #     ruiseki[k]
    # else:
    #     ruiseki[k+i] - ruiseki[i]
    # ans = max(ans, acc[i+k]-acc[i])

Submission status: Accepted

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

m = sum(arr[0:k])
sump = m

for i in range(1, n-k+1):
    sump = sump - arr[i-1] + arr[i+k-1]
    if m < sump:
        m = sump

ans = (m + k) / 2

print(ans)

Submission status: Accepted

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

maxs = target = sum( p[ : k ] )
for i in range( 1, n - k + 1 ):
  target += - p[ i - 1 ]  + p[ i + k - 1 ]
  maxs = max( maxs, target )
ans = ( maxs + k ) / 2 # 各々の期待値は( p + 1 ) /2で求まるから
print( ans )

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
ans = [0] + list(accumulate(map(lambda x: (int(x)+1)/2., input().split())))
print(max([y-x for x,y in zip(ans, ans[K:])]))

Submission status: Accepted

Solution code:
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=sum(B[0:A[1]])
D=C
for i in range(A[1]-1,A[0]-1):
  D=D+B[i+1]-B[i-A[1]+1]
  C=max(C,D)
print((C+A[1])/2)

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
for i in range(N-1):
    p[i+1] += p[i]

ans = []

for i in range(N-K+1):
    if i == 0:
        ans.append(p[K-1])
    else:
        ans.append(p[i+K-1]-p[i-1])
print(max(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from itertools import accumulate
import sys
read = sys.stdin.buffer.read

def main():
  N, K, *p = map(int, read().split())
  p = [0] + list(accumulate(p))
  print((max(b - a for a, b in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = sum([(v+1) for v in p[:K]])
m = a
for i in range(1, N-K+1):
    t = a+(p[i+K-1]+1)-(p[i-1]+1)
    if t > m:
        m = t
    a = t
print(m/2)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

# 期待値の前計算
expP = [(P[i]+1)/2 for i in range(n)]

# 累積和の計算
acc = [0]+ list(accumulate(expP)) # 0を忘れずに

# 隣接する K 項の和の計算
ans = 0
for i in range(n-k+1):
  ans = max(ans,acc[i+k]-acc[i])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def s(n):
    return (n+1)/2

d = list(map(s, p) )

ans = m = sum(d[0:k])
ans_i = 0
# print(ans)
# print(ans/k)
# print(n-k)
for i in range(n-k):
    m -= d[i]
    m += d[i+k]
    # print(m)
    if ans < m:
        ans = m
        ans_i = i + 1

print(ans)
# for i in range(n-k):

Submission status: Accepted

Solution code:
from itertools import accumulate
import sys

def main():
  read = sys.stdin.buffer.read
  N, K, *p = map(int, read().split())
  p = [0] + list(accumulate(p))
  print((max(y - x for x, y in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = sum(sum_p[0:k])
check = sum(sum_p[0:k])
p = 0
for i in range(k,n):
    check = check + sum_p[i] - sum_p[i - k]
    if check > ans:
        ans = check
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ary = np.array([(1 + n) / 2 for n in numbers])

cumsum = ary.cumsum()

max_exv = cumsum[K-1]
for i in range(N - K):
    if cumsum[i+K] - cumsum[i] > max_exv:
        max_exv = cumsum[i+K] - cumsum[i]
    
print(max_exv)

Submission status: Accepted

Solution code:
def main():
  from itertools import accumulate
  import sys
  read = sys.stdin.buffer.read
  N, K, *p = map(int, read().split())
  p = [0] + list(accumulate(p))
  print((max(y - x for x, y in zip(p, p[K:])) + K) / 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

E = [0]*(n+1)

sum_E = 0
max_E = 0

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

for i in range(n-k+1):
  #print(E[i+k] - E[i])
  if max_E < E[i+k] - E[i]:
    max_E = E[i+k] - E[i]
#print(E)
print(max_E)

Submission status: Accepted

Solution code:
#python3

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

m=sum(p[0:k])
ans=[m]
for i in range(k,n):
    m=m+p[i]-p[i-k]
    ans.append(m)
print(0.5*(max(ans)+k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#模範解答の通りにやってみる
N,K=map(int,input().split())
P=list(map(int,input().split()))
if K==1:
	print((max(P)+1)/2)
elif N==K:
	print((sum(P)+N)/2)
else:
	T=sum(P[0:(K)])
	S=sum(P[0:(K)])
	for k in range(0,N-K):
		S=S-P[k]+P[k+K]
		if T<=S:
			T=S
		else:
			continue
	print((T+K)/2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# D
import numpy as np
N, K = map(int,input().split())
p = list(map(int,input().split()))

sums=np.cumsum([(s+1)/2 for s in p])

ans=np.max([ sums[i+K]-sums[i] for i in range(N-K)]+[sums[K-1]])

print(ans )

Submission status: Accepted

Solution code:
def d_dice_in_line():
    from itertools import accumulate
    N, K = [int(i) for i in input().split()]
    P = [int(i) for i in input().split()]

    expected_value = [0] + [(p + 1) / 2 for p in P]
    cumsum = list(accumulate(expected_value))
    return max([cumsum[j + K] - cumsum[j] for j in range(N - K + 1)])

print(d_dice_in_line())

Submission status: Accepted

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

ans = 0
for p in P:
    P_kitaiti.append((1+p)*p/2/p)

for left in range(0, N-K+1):
    if left ==0:
        ans = sum(P_kitaiti[left:left+K])
        now = sum(P_kitaiti[left:left+K])
    else:
        # print(left, left-1, left+K-1)
        now -= P_kitaiti[left-1]
        now += P_kitaiti[left+K-1]
        ans = max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
 
now = sum(p[:K])
saidai = now
for i in range(K, N):
  now -= p[i-K]
  now += p[i]
  if now > saidai:
    saidai = now
 
print('{:.12f}'.format((saidai + K)/2))

Submission status: Accepted

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

summ = sum(P[0:K])
maxi = summ
idx = 0
ans = []
for i in range(N-K):
    summ = summ - P[i] + P[K+i]
    if summ > maxi:
        maxi = summ
        idx = i+1
for j in range(K):
    ans.append((P[idx+j]+1)/2)
print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    N,K = map(int, input().split())
    p = list(map(int, input().split()))
    if N>K:
        esum = [0]*N
        psum = [0]*(N-K)
        esum[0] = p[1]
        for i in range(1,K):
            esum[i] = esum[i-1]+p[i]
        for i in range(K,N):
            esum[i] = esum[i-1]+p[i]
            psum[i-K] = esum[i]-esum[i-K]
        ans = (max(psum)+K)*0.5
    else:
        ans = (sum(p)+K)*0.5

    print(ans)
    return

if __name__=="__main__":
    main()

Submission status: Accepted

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

# 期待値の累積和リストを生成
ex_list = list() 
for i in range(len(p)):
	if i != 0:
		ex_list.append(((1+p[i])/2)+ex_list[-1])
	else:
		ex_list.append((1+p[i])/2)

ans = ex_list[K-1]
for i in range(N-K):
	# print(i,ex_list[i],ex_list[i+K])
	ex = abs(ex_list[i] - ex_list[i+K])
	if ans < ex:
		ans = ex
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int,input().split()))
val = 0
atai = 0
val2 = 0
for i in range(k):
    val2 += p[i]
#print(val2)
val = val2
for i in range(k,n):
    if val < val2:
        val = val2
        atai = i-k+1
    #print(i,p[i],p[i-k])
    val2 += p[i]
    
    val2 -= p[i-k]
    #print(val2)
    if val < val2:
        val = val2

        atai = i-k+1
#print(atai)

#print(atai)
ans = 0
for i in range(k):
    ans += (p[atai]+1)/2
    atai += 1
    #print(atai)
    #print(kitai)
print(ans)

Submission status: Accepted

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

Sim = [0]
for i in range(0,N):
  Sim.append(Sim[i]+Pi[i])
MAX = max(Sim[i+K] - Sim[i] for i in range(N+1-K))

print((MAX+K)/2)

Submission status: Accepted

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

#p = [(n+1)/2 for n in p]
import numpy as np
s = np.cumsum(p)

e=s[K-1]
max_e=(K+e)/2
for i in range(1,N-K):
  e=s[i+K]-s[i]
  e=(K+e)/2
  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()))
val = 0
atai = 0
val2 = 0
for i in range(k):
    val2 += p[i]
#print(val2)
val = val2
for i in range(k,n):
    if val < val2:
        val = val2
        atai = i-k+1
    #print(i,p[i],p[i-k])
    val2 += p[i]
    if i==k:
        val2 == 0
    else:
        val2 -= p[i-k]
    #print(val2)
    if val < val2:
        val = val2

        atai = i-k+1
#print(atai)

#print(atai)
ans = 0
for i in range(k):
    ans += (p[atai]+1)/2
    atai += 1
    #print(atai)
    #print(kitai)
print(ans)

Submission status: Accepted

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

s=0
for i in range(k):
    s += E[i]
    
box=[]
box.append(s)
for i in range(k,n):
    s += E[i] - E[i-k]
    box.append(s)
    
print(max(box))

Submission status: Accepted

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

s = sum(p[:k])
max_s = s

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

    if max_s < s:
        max_s = s

print((max_s + k) / 2)

Submission status: Accepted

Solution code:
import numpy as np

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

res = np.cumsum(E)

ans = res[K - 1]
for i in range(K, N):
    if ans < res[i] - res[i - K]:
        ans = res[i] - res[i - K]
print(ans)

Submission status: Accepted

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

p = [(n+1)/2 for n in p]
import numpy as np
s = np.cumsum(p)

e=s[K-1]
max_e=e
for i in range(0,N-K):
  e=s[i+K]-s[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()))

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

print((k+ans)/2)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = tuple(map(int,input().split()))
MaxSum = sum(p[:K])
tmp_SumSlice = MaxSum
for i in range(K, N):
    tmp_SumSlice = tmp_SumSlice + p[i] - p[i - K]
    if MaxSum < tmp_SumSlice:
        MaxSum = tmp_SumSlice
print((MaxSum+K)/2)

Submission status: Accepted

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

def main():
    N, K, *p = map(int, read().split())
    p = list(map(lambda x: (x+1)*0.5, p))
    p_sum = []
    p_sum.append(p[0])
    for i in range(1, len(p)):
        p_sum.append(p_sum[i-1] + p[i])
    result = p_sum[K-1]
    for i in range(1,N-K+1):
        result = max(result,p_sum[K-1+i] -p_sum[i-1])
    return result

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

Submission status: Accepted

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

p = [(n+1)/2 for n in p]
import numpy as np
s = np.cumsum(p)

e=s[K-1]
max_e=e
for i in range(1,N-K):
  e=s[i+K]-s[i]
  max_e = max(max_e, e)
    
print(max_e)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
num_list = list(map(int, input().split()))
k_sum = sum(num_list[0:b])
max_sum = k_sum
for i, j in zip(num_list[0:], num_list[b:]):
    k_sum -= i
    k_sum += j
    max_sum = max(max_sum, k_sum)
out = (max_sum + b) / 2
print(out)

Submission status: Accepted

Solution code:
from itertools import accumulate


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


expected = [(a+1)/2 for a in A]
accum_expected = list(accumulate(expected))
accum_expected.insert(0, 0)

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))
# 1 - pi
# print(p)
p_cumsum = np.cumsum(p)
# print(p_cumsum)
ans = p_cumsum[k-1]

for i in range(0, n - k):
    # print(i, i + k)
    cum = p_cumsum[i + k] - p_cumsum[i]
    ans = max(ans, cum)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def expected_value(x):
    x = int(x)
    return (x + 1) / 2


def main():
    N, K = map(int, input().split(' '))
    p_list = list(map(expected_value, input().split(' ')))
    cumulative_list = [0]
    for p in p_list:
        cumulative_list.append(cumulative_list[-1] + p)
    max_len = 0
    for i in range(0, N - K + 1):
        if max_len < cumulative_list[i + K] - cumulative_list[i]: max_len = cumulative_list[i + K] - cumulative_list[i]
    print(max_len)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans_max = 0
for i in range(k):
    ans_max += p_dash[i]

temp = ans_max
for i in range(k, n):
    temp = temp - p_dash[i - k] + p_dash[i]
    if(temp > ans_max):
        ans_max = temp

print(ans_max)

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
p = tuple(map(int, sys.stdin.readline().split()))

max = 0
ite = N - K
base = sum(p[0:K])
max = base
index = 0
for i in range(ite):
    tmp = base + p[i+K] - p[i]
    if tmp > max:
        max = tmp
        index = i+1
    base = tmp

E = [(1+p[index+i])/2 for i in range(K)]
print(sum(E))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = input().split()
bubun = [0 for i in range(N)]
sums= [0 for i in range(N+K)]
E=0
S=0

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


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

for i in range(N):
    if i == 0:
        bubun[i] = sums[K-1]
    else:
        bubun[i] = sums[i+K-1]-sums[i-1]

for i in range(N):

    if bubun[i] > S:
        S = bubun[i]


E=(S+K)/2

print(E)

Submission status: Accepted

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

# 期待値
E = [(p+1)/2 for p in P]
#print(E)

# 累積和
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + E[i]
#print(S)

# 隣接K個を取り出して足す
max_E = 0
for i in range(N-K+1):
    tmp_E = S[i+K] - S[i]
    #print(tmp_E)
    if tmp_E > max_E:
        max_E = tmp_E

print(max_E)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
lis_p = map(int, input().split())
def calc_exp(x):
    return (int(x) + 1)/2
lis_exp = list(map(calc_exp, lis_p))
dp= sum(lis_exp[0:K])
cumKsum = sum(lis_exp[0:K])
for i in range(1, N-K+1):
    cumKsum = cumKsum - lis_exp[i-1] + lis_exp[i+K-1]
    dp = max(cumKsum, dp)
print(dp)

Submission status: Accepted

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

for i in range(n-k+1):
    a=s[k+i]-s[i]
    if(m<a):m=a
print(m)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
E = list(map(lambda x: (int(x)+1)/2, input().split()))
E_cumsum = np.cumsum(E)

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

Submission status: Accepted

Solution code:
import numpy as np

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

e = np.array([(pi+1)/2 for pi in p])
es = np.array([sum(e[:k])] + [0]*(n-k))
for i in range(n-k):
  es[i+1] = es[i] - e[i] + e[i+k]

print(es.max())

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x:(x+1)*0.5, p))
temp = []
p_sum=0
for i in range(N):
    p_sum+=p[i]
    temp.append(p_sum)
ans = []
for j in range(K,N):
    ans.append(temp[j]-temp[j-K])
if len(ans) != 0:
    print(max(ans))
else:
    print(p_sum)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
p = list(map(int, input().split()))
p = list(map(lambda x:(x+1)/2, p))
temp = []
p_sum=0
for i in range(N):
    p_sum+=p[i]
    temp.append(p_sum)
ans = []
for j in range(K,N):
    ans.append(temp[j]-temp[j-K])
if len(ans) != 0:
    print(max(ans))
else:
    print(p_sum)

Submission status: Accepted

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

"""
各pの期待値を算出
p期待値について累積和を出す
最大部分和を出す
"""

p_ex = [0] * n

for i in range(n):
    p_ex[i] = (1 + p[i])/2
p_ruiseki = np.cumsum(p_ex)

maxsum = p_ruiseki[k-1]
for i in range(k, n):
    if maxsum < p_ruiseki[i] - p_ruiseki[i-k]:
        maxsum = p_ruiseki[i] - p_ruiseki[i-k]
print(maxsum)

# ruiseki_p = np.cumsum(p)
# maxsum = ruiseki_p[k-1]
# maxindex = -1

# for i in range(k, n):
#     if maxsum < ruiseki_p[i] - ruiseki_p[i-k]:
#         maxsum = ruiseki_p[i] - ruiseki_p[i-k]
#         maxindex = i

# # print(maxsum)
# # print(maxindex)
# # print("---------------")

# ans = 0
# div = 1
# hoge = [[]] * k

# for i in range(k):
#     div *= p[maxindex - i]
#     # print(p[maxindex - i])
#     for j in range(p[maxindex - i]):
#         hoge[i].append(j)


# # print(div)
# # print(hoge)
# print("---------------")


# for i in range(1, p[maxindex-2]+1):
#     for j in range(1, p[maxindex-1]+1):
#         for k in range(1, p[maxindex]+1):
#             ans += (i + j + k) / div
# print(ans)

# # a = [1,2]
# # b = [1,2,3,4]
# # c = [1,2,3,4,5]
# # ex = 0

# # for i in range(2):
# #     for j in range(4):
# #         for k in range(5):
# #             ex += (a[i] + b[j] + c[k])/40

# # print(ex)

Submission status: Accepted

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

ans = sum(a[:k])
b = ans

for i in range(n-k):
    b = b - a[i] + a[i+k]
    if ans < b:
        ans = b       
    
print((k+ans)/2)

Submission status: Accepted

Solution code:
def main():
  def CalExVal(x):
    return (1/2*(x+1))
  N, K = map(int, input().split())
  A = list(map(int, input().split()))


  Ex = list((map(CalExVal, A)))
  #temp = len(A)-K + 1
  #adjlist = [0]*(temp)
  #adjlist = [sum(list(map(CalExVal, A))[i:(K+i)]) for i in range(temp)]
  tem = sum(Ex[:K])
  res = tem
  for i in range(0,N-K):
      tem = tem - Ex[i] + Ex[i+K]
      if res < tem:
      	res = tem
  print(res)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)

Submission status: Accepted

Solution code:
raw = input()
N, K = raw.split(' ')
N = int(N)
K = int(K)
str_li = input().split(' ')
num_li = list(map(int, str_li))
sum_li = [0]
for i in num_li:
    sum_li.append(sum_li[-1] + i + 1)
ans = 0
for index in range(K, N+1):
    ans_tmp = sum_li[index] - sum_li[index - K]
    if ans_tmp > ans:
        ans = ans_tmp
print(ans/2)

Submission status: Accepted

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

max_d = sum(a[0:k])
max_i = 0
total = sum(a[0:k])


for i in range(1,n - k + 1):
    total = total - a[i - 1] + a[i + k - 1]

    if total > max_d:
        max_d = total
        max_i = i

ans = 0
for i in range(max_i,max_i + k):
    ans += (1 + a[i])/2
print("{:7f}".format(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)

Submission status: Accepted

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


t = [0] * (n+k+1)
for i in range(n):
    t[i+1] = t[i] + p[i]

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

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = {}
r = s = m = 0
for i in range(k):
  s += a[i]
  if a[i] in b:
    pass
  else:
    d = a[i]
    b[d] = (d+1)/2.0
m = s
    
for i in range(n-k):
  s = s - a[i] + a[k+i]
  if a[k+i] in b:
    pass
  else:
    d = a[k+i]
    b[d] = (d+1)/2.0
  if m < s:
    m = s
    r = i+1
    
sp = 0.0
for i in range(k):
  sp += b[a[r+i]]
print(sp)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, input().split(' ')))
def In(): return int(input())
def InS(): return input()

N, K = InMap()
P = InMap()

Res = [0]*(N - K + 1)
tmp = sum(P[0:K])
for i in range(K, N):
    Res[i-K] = tmp
    tmp -= P[i-K]
    tmp += P[i]
Res[-1] = tmp
print((max(Res) + K) / 2)

Submission status: Accepted

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

Submission status: Accepted

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

def kitai(x):
  return (1+int(x))/2

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

pre = psum = sum(p[0:k])

for i in range(1, n):
  if i+k > n:
    break
  pre = pre - p[i-1] + p[i+k-1]
  psum = max(psum, pre)

print(psum)

Submission status: Accepted

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline
def main():
    n,k = map(int,input().split())
    l=list(map(int,input().split()))
    l2 = [(1+i)/2 for i in l]
    kitai=sum(l2[0:k])
    tmp = kitai
    for idx in range(n)[:n - k]:
        tmp -= l2[idx]
        tmp += l2[idx+k]
        if (kitai < tmp):
           kitai = tmp
    print(kitai)
main()

Submission status: Accepted

Solution code:
import numpy as np
n,k=map(int,input().split())
exp=list(map(lambda x: (int(x)+1)/2,input().split()))
l=np.cumsum(exp)
 
ans=l[k-1]
for i in range(0,n-k):
  x=l[i+k]-l[i]
  ans=max(ans,x)
print(ans)

Submission status: Accepted

Solution code:

N,K = map(int,input().split())
P_List=list(map(int,input().split()))
#print(N,K)
#print(P_List)

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

def Kitaichi2(p):
    return (p+1)*0.5

kitaichi_list=[]
ruisekiwa_list=[]
ruisekiwa=0
for a in range(N):
    kitaichi_list.append(Kitaichi2(P_List[a]))
    ruisekiwa += Kitaichi2(P_List[a])
    ruisekiwa_list.append(ruisekiwa)

#print(kitaichi_list)
#print(ruisekiwa_list)
pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    if j == 0:
        temp_max = ruisekiwa_list[j+K-1] - 0
    else:
        temp_max = ruisekiwa_list[j+K-1] - ruisekiwa_list[j-1]
    

    if pre_max < temp_max:
        pre_max = temp_max
    temp_max=0

print(pre_max)

Submission status: Accepted

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

print(max([Q[i+K]-Q[i] for i in range(N-K+1)]))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=sum(l[:k])
kai=sum(l[:k])
for i in range(n-k):
    kai+=l[i+k]-l[i]
    ans=max(ans,kai)
print((ans+k)*0.50)

Submission status: Accepted

Solution code:
def expect(n):
    return (int(n)+1)/2
N, K = map(int,input().split()) 
P = list(map(expect,input().split()))
sumlist = [sum(P[0:K])]
sumnumber = sum(P[0:K])
for i in range(N-K):
    sumnumber -=P[i]
    sumnumber +=P[i+K]
    sumlist.append(sumnumber)
print(max(sumlist))

Submission status: Accepted

Solution code:
'''
.append(要素) リストに要素を追加 
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul

f = [int(s) for s in stdin.readline().rstrip().split()]
N = f[0]
K = f[1]
p = list(map(lambda x: 1/2+x/2, [int(s)
                                 for s in stdin.readline().rstrip().split()]))
E = []
tmp = 0
for el in p:
    tmp += el
    E.append(tmp)
past = E[K - 1]
for el in range(len(E)):
    if el - K < 0:
        continue
    e = E[el] - E[el - K]
    if past < e:
        past = e
print(past)

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int,input().split())
q = list(map(int,input().split()))
q = np.array(q)
 
p = (q + 1) /2
p = p.tolist()
a = sum(p[:K])
mx = a
 
for i in range(0,N-K):
    a = a - p[i] + p[i+K]
    if a > mx:
        mx = a
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


def ex(s):
    n = int(s)
    nn = (n+1) * (n/2)
    return nn / n

# main
N, K = mis()
exs = list(map(ex, input().split()))

if N == K:
    print(sum(exs))
    exit(0)

ex_max = 0

for i in range(K):
    ex_max += exs[i]

left = 0
ex_temp = ex_max
for i in range(K, N):
    ex_temp = ex_temp - exs[left] + exs[i]
    left += 1
    if ex_max < ex_temp:
        ex_max = ex_temp

print('{:.7f}'.format(ex_max))