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:
n, k = map(int, input().split())
p = list(map(int, input().split()))
a = 0
b = 0
for i in range(k):
    a += p[i]
    b += p[i]
for i in range(n - k):
    a += p[i + k]
    a -= p[i]
    if b < a:
        b = a
    
print((b + k) / 2)

Submission status: Accepted

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

import numpy as np

Ps = np.array(Ps)

Exp_each_p = (Ps + 1) /2

sum_Exp = [sum(Exp_each_p[0:k])]
if n == 1:
    print(sum_Exp[0])
else:    
    for id in range(1, n - k + 1):
        sum_Exp.append(sum_Exp[id - 1] - Exp_each_p[id - 1] + Exp_each_p[id + k - 1])

    print(max(sum_Exp))

Submission status: Accepted

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

maxstart = 0
maxval = 0
nowval = 0
for i in range(K):
  nowval += p[i]
maxval = nowval
  
for i in range(N-K):
  nowval -= p[i]
  nowval += p[i+K]
  if nowval > maxval:
    maxval = nowval
    maxstart = i+1

ans = 0
for i in range(K):
  ans += (p[i+maxstart] + 1)

print(ans/2)

Submission status: Accepted

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

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

total = sum(P[0: 0 + K])
max_index = 0
P_sum = []
P_sum.append(total)

for i in range(K, len(P)):
    change = P[i] - P[i - K]
    tmp = change + P_sum[-1]
    
    P_sum.append(tmp)

maxx = max(P_sum)
answer = (maxx + K) / 2
print(answer)

Submission status: Accepted

Solution code:
str_N = input().split()
N = int(str_N[0])
K = int(str_N[1])
str_p = input().split()
p = [float(str_p[i]) for i in range(N)]

ans = 0
e_sum = 0

for j in range(K):
  e_sum = e_sum + (p[j]+1)/2

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

print(ans)

Submission status: Accepted

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

ansl = 0
ansr = k-1
ans = 0
tmp = sum(p[:k])
# print(tmp)
for i in range(1,n - k+1):
    tmp = tmp - p[i-1] + p[i + k-1]
    # print(i,i+k-1,tmp)
    if tmp > ans:
        ansl = i
        ansr = i + k - 1
        ans = tmp
# print(ansl, ansr)
ans2 = 0
for i in range(ansl, ansr + 1):
    ans2 += (p[i] + 1) / 2
print(ans2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
    
    
#s = [0] * (N-K)

s = 0
for j in range(K):
    s += p[j]

sm = s

for i in range(N-K):
 #   s[i] = 0
    s = s + p[K+i]- p[i]
    if s > sm:
        sm = s

print( sm/2+0.5*K)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num_lis = list(input().split())
max = 0
c = 0
for i in range(n):
    num_lis[i] = int(num_lis[i])
for i in range(n-k+1):
    if i == 0:
        for j in range(k):
            c = c + num_lis[i+j]/2 + 1/2
        max = c
    else:
        c = c - num_lis[i-1]/2 + num_lis[i+k-1]/2
        if c > max:
            max = c
print(max)

Submission status: Accepted

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

p = list(map(int,input().split()))
counter_li = []
first = 0
for i in range(k):
    first+=p[i]
counter_li.append(first)
for i in range(1,len(p)-k+1):
    counter_li.append(counter_li[i-1]+ p[i+k-1] - p[i-1])
print(max(counter_li)/2+k/2)

Submission status: Accepted

Solution code:
from itertools import accumulate
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
A = (A+1)/2

B = np.insert(A,0,0)
B = list(accumulate(B))
answer = []
for i in range(N-K+1):
    answer.append(B[i+K]-B[i])

print(max(answer))

Submission status: Accepted

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

pmax=sum(pi[0:k])
#print(pmax)
psum=pmax
for i in range(1,n-k+1):
    psum=psum-pi[i-1]+pi[i+k-1]
#    print(i,k,psum)
    if psum>pmax:
        pmax=psum
px=(k+pmax)/2
print(px)

Submission status: Accepted

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

for i in range(N-K):
    f = f + p[i+K] - p[i]
    a[i+1] = f

print(max(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_i = list(map(int,input().split()))
answer = 0
sum = 0
for x in range(n):
    if x <= k - 1: 
        sum += p_i[x]
        if x == k - 1: answer = sum
    else:
        sum += p_i[x] - p_i[x - k]
        answer = max(answer, sum)
print((answer + k) / 2)

Submission status: Accepted

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

exp = [(x+1)*0.5 for x in p]

sums = []
sums.append(0.0)
for i in range(1,N+1):
    sums.append(sums[i-1]+exp[i-1])

#print(sums)
ans = 0.0
for i in range(N-K+1):
    if ans < sums[i+K] - sums[i]: ans = sums[i+K] - sums[i];

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

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

# 最初のsum
sum_EV = 0
for i in range(K):
  sum_EV = sum_EV + EV_p_list[i]

# それ以降の比較
max_EV = sum_EV
for i in range(1, N - K + 1):
  sum_EV = sum_EV - EV_p_list[i - 1] + EV_p_list[i + K - 1]
  if sum_EV > max_EV:
    max_EV = sum_EV

print(max_EV)

Submission status: Accepted

Solution code:
def calc_E(prob):

    E = (prob + 1) / 2
    return E

def main(N, K, list_p):
    
    list_E = list(map(calc_E, list_p))
    max_E  = sum(list_E[0:K])
    prev_E = sum(list_E[0:K])

    for i in range(1, N-K+1):
        tmpE   = prev_E - list_E[i-1] + list_E[i-1+K]
        max_E  = max(max_E, tmpE)
        prev_E = tmpE

    return max_E
        


if __name__ == "__main__":

    [N, K] = list(map(int, input().split(' ')))
    list_p = list(map(int, input().split(' ')))

    answer = main(N, K, list_p)
    print(answer)

Submission status: Accepted

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

firstValue =  (r[0] / 2) + 0.5

#最初の1セットを計算して、maxSumと前回結果に設定
firstSet = r[0:k]
tempMax = 0
for p in firstSet:
    tempMax += (p / 2) + 0.5

maxSum = tempMax
beforeSum = tempMax

for i in range(k,n):
    lastValue = (r[i] /2)+0.5
    nowValue = beforeSum - firstValue + lastValue
    if nowValue > maxSum:
        maxSum = nowValue

    beforeSum = nowValue
    firstValue = (r[i-k+1]/2)+0.5

print(maxSum)

Submission status: Accepted

Solution code:
import numpy
a,b = map(int,input().split())
li = list(map(int,input().split()))
L = [(i**2+i)/(2*i) for i in li]
dp=[0]*a
res = numpy.cumsum(L)
dp[0] = res[b-1]
for i in range(1,a-b+1):
    dp[i] = res[i+b-1]-res[i-1]
print(max(dp))

Submission status: Accepted

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

S = [0]
before = 0
for i in range(N):
    S.append(P[i]+before)
    before += P[i]

max_num = 0
l = 0
m = 0
for i in range(N):
    if K+i > N:
        break
    tmp = S[K+i]-S[i]
    if tmp > max_num :
        l = K+i
        m = i
        max_num = tmp

S = P[m:l]
ans = 0
for i in range(len(S)):
    gausu = (S[i])*(S[i]+1)/2
    ans += (gausu/S[i])

print(ans)

Submission status: Accepted

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

kitai = [None]*(1001)
for i in range(1, 1001):
    kitai[i] = (0.5*i*(i+1))/i

ruiseki = P.copy()
ruiseki[K-1] = sum(ruiseki[0:K])
for i in range(K, N):
    ruiseki[i] = ruiseki[i-1]+P[i]-P[i-K]

ind = np.array(ruiseki).argmax()
temp = P[ind-K+1:ind+1]
ans = 0
for t in temp:
    ans+=kitai[t]
print(ans)

Submission status: Accepted

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

dp = [0] * n
m = {}

def func(x):
    return m.get(x, sum(range(x+1)) / x)
    #return sum(range(x+1)) / x

for i in range(n):
    if i - k >= 0:
        dp[i] = dp[i - 1] - func(P[i - k]) + func(P[i])
    else:
        dp[i] += func(P[i]) + dp[i-1]

print(max(dp))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp_sum = sum(p[0:k])
ans = (tmp_sum + k) / 2
count = float(0)
for i in range(k, n):
    tmp_sum = tmp_sum + p[i] - p[i - k]
    tmp = (tmp_sum + k) / 2
    if ans <= tmp:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)

Submission status: Accepted

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


j = n-k
s = p[0:k]
max = sum(s)
su = max

for i in range(j):
    t = su+p[i+k]
    u = t-p[i]
    if max < u:
        max = t-p[i]
        s = p[i+1:i+1+k]

    su = u

def summ(i):
    return i*(i+1)/2

ss = 0


for i in s:
    ss += summ(i)/i

print(ss)

Submission status: Accepted

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

sum_max = sum(p[0:k])
sum_temp = sum_max

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

s_max = (sum_max + k) / 2

print(s_max)

Submission status: Accepted

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

    def e(dice):
        ans = 0
        for r in range(1, dice+1):
            ans += r /dice
        return ans

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

    p_cum = [0] + list(accumulate(p))

    ma = 0
    ind = 0
    for i in range(k, n+1):
        temp = p_cum[i] - p_cum[i-k]
        if ma < temp:
            ma = temp
            ind = i

    x = p[ind-k:ind]

    print(sum(e(d) for d in x))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def E(n):
  return n*(1+n)/2/n

n, k = map(int, input().split())
l = list(map(int, input().split()))
ex = []
exsum = [0] *300000

tmpmax = 0
for i in range(n):
  ex.append(E(l[i]))

for i in range(n-k+1):
  if i == 0:
    for j in range(k):
      tmpmax += ex[i+j]
      exsum[i] = tmpmax
  else:
    exsum[i] = exsum[i-1] - ex[i-1] + ex[i+k-1]
  
a = exsum.index(max(exsum))

print(exsum[a])

Submission status: Accepted

Solution code:


n, k= [0] * 2
p = []

def format_input(filename = None):
	global n, k
	global p
	if filename == None:
		n, k = list(map(int, input().split()))
		p = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(1, 2 * 10**5)
		k = rng(1, n)
		p = [rng(1, 10**3) for i in range(n)]

def get_answer():
	e = []
	e.append(sum(p[0:k]))
	for i in range(n - k):
		e.append(e[i]-p[i]+p[i+k])
	e.sort()
	answer = float(e.pop() + k) / 2.0
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

ex = []
for i in range(1001):
    e = 0
    j = i 
    while j != 0:
        e += j / i
        j-=1
    ex.append(e)

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

total = 0
mx = 0

for i in range(n):
    if i < k:
        total += ex[p[i]]
    else:
        total = total + ex[p[i]] - ex[p[i-k]]
    if mx < total:
        mx = total

print(mx)

Submission status: Accepted

Solution code:
# D - Dice in Line

n,k=map(int, input().split())
p=list(map(int, input().split()))
q=[0]*n

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

max=0
for i in range(k):
    max+=q[i]

sum=max
for i in range(1, n-k+1):
    sum=sum-q[i-1]+q[i+k-1]
    if sum > max:
        max=sum
print(max)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
X = list(map(int, input().split()))
from itertools import accumulate
for i in range(N):
    X[i] = 1 + (X[i]-1)/2

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

Submission status: Accepted

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

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

raw_max = sum(P[0:K])
maxnum = 0
sum_tmp = sum(P[0:K])

for i in range(1, N-K+1):
    sum_tmp = sum_tmp - P[i-1] + P[i+K-1]
    if(raw_max < sum_tmp):
        raw_max = sum_tmp
        maxnum = i

ev_max = [(n+1)/2 for n in P[maxnum:maxnum+K]]

print(sum(ev_max))

Submission status: Accepted

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

d = []
d.append(sum(p[:k]))

for i in range(1,n-k+1):
  d.append(d[i-1] - p[i-1] + p[i-1+k])

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

Submission status: Accepted

Solution code:
N, K=map(int, input().split())
Pn=list(map(int, input().split()))
V = [0] * N
ans = [0] * K
max_v = 0
sum_v = 0
for n in range(N):
    V[n] = (0.5*Pn[n]*(Pn[n]+1))/Pn[n]
    if n < K:
        sum_v += V[n]
        max_v = sum_v
    else:
        sum_v = sum_v - V[n-K] + V[n]
        max_v = max(max_v, sum_v)
print(max_v)

Submission status: Accepted

Solution code:
def main():
    N,K = map(int, input().split())
    pi = list(map(int, input().split()))
    max_num = 0
    new_pi = [0] * N
    sum_new_pi = [0] * (N+1)

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

    for i in range(N):
        sum_new_pi[i+1] = sum_new_pi[i] + new_pi[i]

    for i in range(N):
        if i+K > N:
            break
        s = sum_new_pi[i+K] - sum_new_pi[i]
        if s > max_num:
            max_num = s

    print(max_num)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

A=[]
base=0
B=[]

for i in range(N):
    if p[i]%2==0:
        A.append(((p[i]+1)*p[i]//2)/p[i])
    else:
        A.append((((p[i]+1)*(p[i]//2)+((p[i]+1)//2)))/p[i])
    
for l in range(K):
    base+=A[l]
B.append(base)
for k in range(K,N):
    base+=A[k]
    base-=A[k-K]
    B.append(base)    

print(max(B))
#print(A)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ruiseki = []
a = 0
for i in range(n):
  a += p_list[i]
  ruiseki.append(a)
res = -1
val_list = []
for m in range(n-k):
  val = ruiseki[k+m] - ruiseki[m]
  val_list.append(val)
if n ==k :
  	print((sum(p_list) + k)/2)
else:
	print((max(val_list)+k)/ 2)

Submission status: Accepted

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

psum = []
pini = sum(p[:K])
psum.append(pini)
for i in range(1, N-K+1):
    pini = pini - p[i-1] + p[i+K-1]
    psum.append(pini)
print((max(psum)+K)/2)

Submission status: Accepted

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

tmp = sum(ps[:k])
max_ps = tmp
start = 0

for i in range(1,n-k+1):
    tmp = tmp-ps[i-1]+ps[i+k-1]
    if tmp >= max_ps:
        max_ps = tmp
        start = i

print(sum([(i*(i+1))/ (2*i) for i in ps[start:start+k]]))

Submission status: Accepted

Solution code:
import numpy
N, K = map(int, input().split())
p = numpy.array(list(map(int, input().split())))
max = 0
nowsum = 0
for i in range(N-K+1):
    if i == 0:
        nowsum = numpy.sum(p[i:i+K])
    else:
        nowsum = nowsum - p[i-1] + p[i+K-1]
    if max < nowsum:
        max = nowsum
        maxno = i

exsum = 0

for i in range(K):
    temp = p[i+maxno]
    exsum += (0.5*temp*(temp+1))/temp
print(exsum)

Submission status: Accepted

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

e = []

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

ans = sum(e[0:k])
s = ans

for i in range(k,n):
  aaa = s + e[i] - e[i-k]
  if ans < aaa:
    ans = aaa
  s = aaa
print(ans)

Submission status: Accepted

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

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

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

print((total_max + k) / 2)

Submission status: Accepted

Solution code:

N , K = map( int , input().strip().split(" ") ) ; 
LL = [] ;
for x in input().strip().split(" " ) :
	k = int(x ) ;
	LL.append(  ( k * ( k + 1 ) ) / k / 2 ) ;

LL2 = [] ;
LL2.append( LL[0] ) ;
for x in range ( 1 , len( LL ) ) :
	LL2.append( LL2[-1] + LL[x] ) ;



v0 = 0 ;
for x in range ( K-1 , N  ) : 
	d = 0. if x - K < 0 else LL2[x-K];
	v = LL2[x] -d ;
	v0 = max ( v , v0 ) ;
print ( "{0:.8f}".format(  v0 ) ) ;

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
nums = []
elm = 0
for num in p:
    elm += (num * (num + 1) / 2) * (1 / num)
    nums.append(elm)
maxVal = nums[k-1]
for i in range(n - k):
    if nums[i + k] - nums[i] >= maxVal:
        maxVal = nums[i + k] - nums[i]
    else:
        continue
print(maxVal)

Submission status: Accepted

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

import numpy as np

data = np.fromstring(read(), np.int64, sep=' ')

N, K  = data[:2]
P = data[2:] + 1

Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]
print(length_K_sums.max() / 2)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    temp=0
    max=sum(p[0:k])
    maxi=0
    temp=max
    if n>=2:
        for i in range(1,n-k+1):
            temp-=p[i-1]
            temp+=p[i+k-1]
            if temp>max:
                max=temp
                maxi=i
    total=(max+k)/2
#    for i in range(maxi,maxi+k):
 #       total+=(1+p[i])

    print(total)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def Main(N, K, P):
    wa = sum(P[:K])
    max_sum = wa
    max_sum_ind = 0
    for i in range(N-K):
        wa = wa - P[i] + P[i+K]
        if(wa > max_sum):
            max_sum = wa
            max_sum_ind = i
    ans = 0
    if max_sum_ind == 0:
        for i in range(K):
            ans += (P[i]+1)/2
    else:
        for i in range(max_sum_ind+1, max_sum_ind+K+1):
            ans += (P[i]+1)/2
    return ans

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    print("{:.12f}".format(Main(N, K, P)))

if __name__ == '__main__':
    main()

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
    
ans = 0
max_index = 0
# left = 0
# right = k
max_ruiseki = sum(p[0:k])
now_ruiseki = 0
ruiseki = [max_ruiseki]
for left in range(n-k+1):
    if left != 0:
        right = k + left 
        # print(left-1, p[left-1])
        
        # print(right-1 ,p[right-1])
        new_ruiseki = ruiseki[left-1] + p[right-1] - p[left-1]
        ruiseki.append(new_ruiseki)

# print(ruiseki)
m = 0
max_index = 0
for i in range(len(ruiseki)):
    if m != max(m, ruiseki[i]):
        m = ruiseki[i]
        index = i

# print(index)

A = p[index:index+k]
    # now_ruiseki = max_ruiseki
for a in A:
    ans += kitai(a)
print(ans)

    



# next_ruiseki = 0
# for i in range(n-k+1):
#     next_ruiseki = ruiseki    
#     ruiseki = max(ruiseki)


    # A
    # A = p[i:i+k]
    # if c != max(c, sum(A)):
    #     c = sum(A)
    #     C = deepcopy(A)
# for a in C:
#     ans += kitai(a)
# print(ans)

Submission status: Accepted

Solution code:

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

p_shift = p[k:] + [0] * k

con_p = [0] * dices
sum_first_k = sum(p[0:k])

con_p[0] = sum_first_k

for i in range(dices-k):
    con_p[i+1] = con_p[i] + p_shift[i] - p[i]

max_expectation = (k + max(con_p))/2.
print(max_expectation)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

ac = [0] + list(accumulate(map(lambda x: (1 + x) / 2, p)))
ans = max(ac[i+k] - ac[i] for i in range(n - k + 1))
print(ans)

Submission status: Accepted

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

P_ave_sum = []
ave = 0
for p in P:
    ave += (p + 1) / 2
    P_ave_sum.append(ave)



max = -1
if n == k:
    max = P_ave_sum[n - 1]
else:
    for j in range(n - k):
        sum_k = P_ave_sum[j + k] - P_ave_sum[j]
        if sum_k > max:
            max = sum_k

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

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

m = []
for i in range(n):
    a = gauss(p[i]) / p[i]
    m.append(a)

ans = 0
for i in range(k):
    ans += m[i]

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy import signal

def main():
    N, K = map(int, input().split(" "))
    P = np.array(list(map(int, input().split(" "))))

    e = (P + 1) / 2

    t = np.ones((K))

    print(np.amax(
        signal.fftconvolve(
            e,
            t
        )
    ))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def summ(a):
    for i in range(1,a):
        a += a-i
    return a

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

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

max_value = 0

for i in range(0,len(s)-k):
    if(s[i+k] - s[i] > max_value):
        max_value = s[i+k] - s[i]
        max_start = i

ans_pre = []

for j in range(k):
    ans_pre.append(p[max_start + j])

ans = 0.0

for i in range(len(ans_pre)):
    ans += ((ans_pre[i]*(1+ans_pre[i]))/2)/ans_pre[i]
print(ans)

Submission status: Accepted

Solution code:
# D
N, K = map(int, input().split())
lst = list(map(int, input().split()))
lst1 = [(lst[0] + 1) / 2]
ma = 0
for i in range(1, len(lst)):
    lst1.append(lst1[i-1] + ((lst[i]+1) / 2))
    if (i >= K):
        ma = max(ma,lst1[i] - lst1[i-K])
ma = max(ma,lst1[K-1])
print(ma)

Submission status: Accepted

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

history = {}

top3 = []

result = 0

def calc_expect_sum(targets):
    return sum( (p+1) * 0.5 for p in targets)

prev_sum = calc_expect_sum(ps[0:0+k])
result = 0

if n == k:
    print(calc_expect_sum(ps))
else:
    for i in range(1,n-k+1):
        prev = ps[i-1]
        current = ps[i+k-1]
        diff = (current - prev) * 0.5
        new = prev_sum + diff
        if new > result:
            result = new
        prev_sum += diff
    
    print(result)

Submission status: Accepted

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

m=sum(s[0:k])
r=[m,]
b=m

for i in range(n-k):
  b=b-s[i]+s[i+k]
  r.append(b)
r.sort()
print((r[-1]+k)/2)

Submission status: Accepted

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

print(s_max/2+k/2)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = list(map(int, input().split()))
C = list(map(int, input().split()))
A=[]
for i in range(N):
  A.append((C[i]+1)/2)
B = [0] + A
B = list(accumulate(B))

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
pis = list(map(int, input().split()))
sum_max = 0
sum_cd = 0
for i in range(k):
  sum_max += pis[i]
  sum_cd += pis[i]
for j in range(1,n-k+1):
  sum_cd -= pis[j-1]
  sum_cd += pis[j+k-1] 
  if sum_cd > sum_max:
    sum_max = sum_cd
expect = sum_max/2 + k / 2
print(expect)

Submission status: Accepted

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

sum_max = 0
temp = 0

for i in range(K):
    temp += (lst[i]+1)/2
    sum_max = temp
for j in range(0,N-K):
        temp += (lst[j+K]-lst[j])/2
        if temp > sum_max:
            sum_max = temp
            
print(sum_max)

Submission status: Accepted

Solution code:
from itertools import accumulate
N,K = map(int,input().split(" "))
p = list(map(int,input().split(" ")))
pp = list(accumulate(p))
ans = (pp[K-1]+K)/2
for i in range(N-K):
    ans = max(ans,(pp[i+K]-pp[i]+K)/2)
print(ans)

Submission status: Accepted

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

ret = []
s0 = sum(p[0:K-1])
for x in range(0,N-K+1):
    s0 = s0 + p[x+K-1]
    ret.append(s0)
    s0 = s0 - p[x]
print((max(ret)+K)/2)

Submission status: Accepted

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

def main():
    n,k = map(int, input().split())
    l = list(map(mean, input().split()))
    out = sum(l[:k])
    result = out

    for i in range(1, len(l)-(k-1)):
        result = result - l[i-1] + l[i+k-1]

        if out < result:
            out = result

    print(out)

def mean(x):
    x = int(x)
    return x * (x+1) / (2 * x)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

mx = sum(ps[:k])
sm = sum(ps[:k])
for i in range(k, n):
  sm += ps[i] - ps[i-k]
  if sm > mx:
    mx = sm
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res=[]

res.append((sum(range(1,p[0]+1)))/p[0])

for i in range(1,N):
    res.append(res[i-1]+1+0.5*(p[i]-1))
ans=res[K-1]

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