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:
# s, t = input().split(" ")
n, k = map(int, input().split())

#A = []
A = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
import sys
import itertools 

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,K = MI()
	p = LI()
	for i in range(N):
		p[i] = (1+p[i])*(1/2)
	p=[0]+list(itertools.accumulate(p))
	ans = -1
	for i in range(K,N+1):
		s = p[i]-p[i-K]
		if(ans < s):ans=s
	print(ans)


main()

Submission status: Accepted

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

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

for i in range(n-k):
  exp += (1 + p[i+k]) / 2
  exp -= (1 + p[i]) / 2
  if exp_true < exp:
    exp_true = exp

print(exp_true)

Submission status: Accepted

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

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

ans =0
if N-K>0:
    for i in range(N-K):
        ans = max(a[i+K] - a[i], ans)
else:
    ans = a[-1]
print("{0:.8f}".format((ans+K)*0.5))

Submission status: Accepted

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

    tmp_max = sum(p[:K])
    tmp = sum(p[:K])
    for i in range(N-K):
        tmp += p[K+i]
        tmp -= p[i]

        if tmp > tmp_max:
            tmp_max = tmp

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

x = [0] * (n-k+1)
x[0] = sum([(i+1)/2 for i in p[:k]])
for i in range(1, n-k+1):
    x[i] = x[i-1] + (-p[i-1] + p[i+k-1])/2

print(max(x))

Submission status: Accepted

Solution code:
import numpy as np
K,N = list(map(int,input().split()))
arr = np.array(list(map(int,input().split())))
arr = arr.cumsum()
_sum = 0
for i in range(len(arr)-N+1):
  if i==0:
    tmp = arr[N-1]
  else:
    tmp = arr[N+i-1]-arr[i-1]
  _sum = max(_sum,tmp)

print((_sum+N)/2)

Submission status: Accepted

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

Submission status: Accepted

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

l = []
tmp = 0
#O(N)
for i in range(K):
    a= (p[i]+1)/2
    tmp+=a
    l.append(a)
ans = tmp
for i in range(K,N):
    a = (p[i]+1)/2
    l.append(a)
    b = l[i-K]
    tmp += a
    tmp -= b
    ans=max(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  9 20:53:23 2020

@author: H_Hoshigi
"""

N, K = map(int, input().split())
p_list = list(map(int, input().split()))
E_list = [(1+p)/2 for p in p_list]

moving_sum_E_K_list = [sum(E_list[0:K])]
max_msEK = moving_sum_E_K_list[0]
for i in range(N-K):
    msEK = moving_sum_E_K_list[-1] - E_list[i] + E_list[K+i]
    moving_sum_E_K_list.append(msEK)
    max_msEK = max(max_msEK, msEK)

print(max_msEK)
#print(p_list)
#print(E_list)
#print(moving_sum_E_K_list)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def run():
  N, K = map(int, input().split())
  ps = list(map(int, input().split()))
  dp = [0]*(N-K+1)
  ans = 0
  dp[0] = sum(ps[0:K])
  for n in range(1, N-K+1):
    dp[n] = dp[n-1]+ps[n+K-1]-ps[n-1]
  print((max(dp)+K)/2)

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
add = [None]*(n-k+1)
add[0] = sum(p[:k])

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

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

Submission status: Accepted

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

Submission status: Accepted

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

    pN_ = []

    ans = 0
    total = 0
    for i, s in enumerate(input().split()):
        total += 1 + int(s)
        pN_.append(total)

        if i == K - 1:
            ans = max(ans, (total / 2))
        elif K <= i:
            ans = max(ans, (total - pN_[i - K]) / 2)

    print(ans)


main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
maxer = sum(p[:k])
cnt = maxer
st = 0
for i in range(n-k):
    cnt = cnt - p[i] + p[i+k]
    if cnt >= maxer:
        maxer = cnt
        st = i+1
ans = 0
for i in range(st,st+k):
    if p[i]%2 == 0:
        ans += (p[i]//2+0.5)
    else:
        ans += (p[i]//2 + 1)
print(ans)

Submission status: Accepted

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

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

L2 = [0] * (N + 1)
for i in range(N):
    L2[i+1] = L2[i] + L[i]

x = 0
for i in range(N - K + 1):
    x = max(x, L2[i+K] - L2[i])

print(x)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
sums=[sum(j for j in range(i+1)) for i in range(1001)]
ans=0

for i in range(K):
    ans+=sums[P[i]]/P[i]
tmp=ans

for i in range(K,N):
    l=sums[P[i-K]]/P[i-K]
    r=sums[P[i]]/P[i]
    tmp=tmp-l+r
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0.0
for j in range(k):
  a+=float(i[j+place]+1)/2
print(a)

Submission status: Accepted

Solution code:
def check(A):
  s = 0
  print(A)
  for i in A:
    s += (1+i)/2
    print(s)
  return s



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

now = 0
s = 0
for i,j in enumerate(p):
  if i <= K-1:
    s += (j+1)/2
  else:
    s -= (p[i-K]+1)/2
    s += (j+1)/2
  if now < s:
    now = s
  

print(now)

Submission status: Accepted

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

sk = sum(p[:k])
st = p[0]
c = 0
mp = sk

for i in range(k, n):
    sk = sk - p[i-k] + p[i]
    if mp < sk:
        mp = sk

print((mp+k)/2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def calc_expect(n):
    return (n+1) / 2


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

p_expect_list = list(map(calc_expect, p_list))

max_val = 0

res = [0] * len(p_expect_list)
res[0] = p_expect_list[0]
for i in range(len(res)-1):
    res[i+1] = res[i] + p_expect_list[i+1]

if (n == k):
    print(res[-1])
    exit()

for i in range(len(p_expect_list)-k):
    val = res[i+k]-res[i]
    if val > max_val:
        max_val = val

print(max_val)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
pwa=[0 for i in range(n+1)]
ruiwa=[0 for i in range(n+1)]
ruiwa[0]=0
pwa[0]=0
for i in range(1,n+1):
  ruiwa[i]=ruiwa[i-1]+p[i-1]
for i in range(1,n-k+2):
  pwa[i]=ruiwa[i+k-1]-ruiwa[i-1]
ans=(max(pwa)+k)/2
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]+1)/2

result=0
result+=total
for i in range(1,N-K+1):
   total=total-(p[i-1]+1)/2+(p[i+K-1]+1)/2
   result=max(result,total)

print(result)

Submission status: Accepted

Solution code:
nk=input().split(" ")
N=int(nk[0])
K=int(nk[1])
p=input().split(" ")
p=[int(s)+1 for s in p]

max_sum=0
cur_sum=0
for i in range(K):
  cur_sum+=p[i]
max_sum=cur_sum
for i in range(1,N-K+1):
  cur_sum+=p[i-1+K]-p[i-1]
  max_sum=max(max_sum,cur_sum)
print(max_sum/2.0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

N, K = map(int,input().split())
P = list(map(int,input().split()))
Q = [(1.0+P[i])/2.0 for i in range(N)]

lst = []
Q.insert(0, 0)
P_cumsum = np.cumsum(Q)

for i in range(N-K+1):
  var = P_cumsum[K+i] - P_cumsum[i]
  lst.append(var)
  
ans = max(lst) * 1.0

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

pre_ans = 0
ans = 0
for i in range(K):
    ans += (P[i] + 1) / 2
    pre_ans += (P[i] + 1) / 2
#print("first_ans={}".format(ans))

for i in range(N - K):
    pre_ans = pre_ans + (P[K + i] + 1) / 2 - (P[i] + 1) / 2
    ans = max(ans, pre_ans)
    #print("{}-, cand={}, ans={}".format(i+1, pre_ans, ans))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
E = [0] * N
E[0] = sum(P[:K])

for i in range(1, N-K):
  E[i] = E[i-1] + P[i+K-1] - P[i-1]

E[N-K] = sum(P[N-K:])
maxE = max(E)
#print(E)
print((maxE - K) / 2.0 + K)

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 = np.hstack([[0], data[2:] + 1])

Pcum = P.cumsum()
x = Pcum[K:] - Pcum[0:-K]
print(x.max() / 2)

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    P = [int(x) for x in stdin.readline().rstrip().split()]
    E = [((p*(p+1))/2)/p  for p in P]
    maxe = sum(E[0:0+K])
    frontval = maxe
    for i in range(1, N-K+1):
        val = frontval - E[i-1] + E[i+K-1]
        frontval = val
        if maxe < val:
            maxe = val
    print(maxe)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
want = sum(p[0:K])
change = sum(p[0:K])

for i in range(1,N-K+1):
    change = change - p[i-1] + p[i+K-1]
    want = max(change,want)

print((K+want)/2)

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 += P[i+K] - P[i]
  m = max(m, s)
print((m + K) / 2)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = [int(i) for i in input().split()]
x = [0]*(max(p)+1)
for i in range(1,len(x)):
    x[i] = x[i-1] + i
for i in range(1,len(x)):
    x[i] /= i

s = 0
for i in range(k):
    s += x[p[i]]
ans = s

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
P = list(map(int,input().split()))
Ex = [0 for _ in range(N)]
for i in range(N):
    Ex[i] = P[i]*(P[i]+1)/(2*P[i])
wa = 0
for i in range(K):
    wa += Ex[i]
maxi = wa
for i in range(N-K):
    wa = wa - Ex[i] + Ex[K+i]
    maxi = max(maxi,wa)
print(maxi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = list(map(int,input().split()))

ans = 0
for i in range(m):
    ans += l[i]
a = ans
for i in range(m,n):
    a = a+l[i]-l[i-m]
    if a > ans:
        ans = a
print((ans+m)/2)

Submission status: Accepted

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

def f(p):
    #(p*(p+1)/2)/p
    return (p+1)/2


p2 = []

for p_tmp in p:
    p2.append(f(p_tmp))

p3 = [p2[0]]

for i in range(1,len(p2)):
    p3.append(p2[i]+p3[i-1])

ans = p3[k-1]
for i in range(k,n):
    ans = max(ans,p3[i]-p3[i-k])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#D
import numpy as np
n, k = map(int, input().split())
p = list(map(int, input().strip().split()))
p = np.array(p)
def calc_E(p):
    return ((p+1)/2)

q = (p+1)/2

#print(q)
sum = np.cumsum(q)

sum2 = np.zeros((n+1))
sum2[1:] = sum
max = -1
for i in range(k,n+1):
    tmp = sum2[i] - sum2[i-k]
    if max < tmp:
        max = tmp

print(max)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *P = map(int, read().split())

P_ = [0] * N

acc = sum(P[:K])
ans = (acc + K) / 2

for i in range(N - K):
    acc -= P[i]
    acc += P[i + K]
    ans = max(ans, (acc + K) / 2)

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
P = list(map(float,input().split()))
for i in range(N):
    P[i] = (P[i]+1.0)/2.0

anss=0        
for i in range(N-K+1):
    #print(i)
    #ans_kari = sum(P[i:i+K])
    if i==0:
        ans_kari = sum(P[i:i+K])
    else:
        ans_kari = ans_kari - P[i-1] + P[i+K-1]
    #print(ans_kari)
    #print(i)
    if ans_kari > anss:
        anss = ans_kari

print(anss)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
P = list(map(int, input().split()))
A = [0] * n
A[0] = P[0]
for i in range(1, n):
  A[i] = P[i] + A[i-1]
A = [0] + A
#print(A)

max = 0
max_i = 0
for i in range(n - k + 1):
  total = A[i+k] - A[i]
  if max < total:
    max = total
    max_i = i
#print(max, max_i)
print((max + k) / 2)

Submission status: Accepted

Solution code:
N, K = map(int,input().split()) # 複数の数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

result = []
num = 0

for i in range(K):
    num += List[i]

result.append(num)
    
for i in range(N-K):
    num = num - List[i] + List[K+i]
    result.append(num)

print(max(result) / 2 + 0.5*K)

Submission status: Accepted

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

def solve():
    N, K = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    kitai = []  # kitai[i] := p[i]の期待値
    for p in Ps:
        kitai.append(((1+p)*p/2)*(1/p))

    # 尺取法でさがすぜ
    # まずは初期状態を計算する
    ans = 0
    for i in range(0, K):
        ans += kitai[i]

    # つぎにしゃくとっていくぜ
    total = ans
    for i in range(K, N):
        total = total + kitai[i] - kitai[i-K]
        if total > ans:
            ans = total

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def solve():
    N, K, *p = map(int, open(0).read().split())
    
    idx = 0
    tmp, p_sum = sum(p[:K]), sum(p[:K])
    for i in range(N - K):
        tmp -= p[i]
        tmp += p[i + K]
        if p_sum < tmp:
            p_sum = tmp
            idx = i + 1
    
    cumsum = [i for i in range(1, 200001)]
    for i in range(1, 200000):
        cumsum[i] += cumsum[i - 1]
    
    ans = 0
    for i in range(idx, idx + K):
        ans += cumsum[p[i] - 1] / p[i]
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np

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

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

e = (p + 1) / 2

ans = 0
sum = 0

for i in range(n - k + 1):
    if i == 0:
       ans = np.add.reduce(e[:k])
       sum = np.add.reduce(e[:k])

    else:
        sum = sum - e[i-1] + e[i+k-1]
        if ans < sum:
            ans = sum + 1 - 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

sum_p = sum(p_list[0:K])
ans = sum_p
for i in range(1, N-K+1):
  sum_p = sum_p - p_list[i-1] + p_list[i+K-1]
  if ans < sum_p:
    ans = sum_p

print(ans)

Submission status: Accepted

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

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

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

# r, l = 0, 0
# su = 0
# ans = 0
# while r < n:
#     if r - l >= k-1:
#         su -= p[r]
#         r += 1
#         ans = max(ans, su)
#     else:
#         l += 1
#         su += p[l]
su = sum(p[:k])
ans = su
for i in range(k, n):
    su += p[i]
    su -= p[i-k]
    ans = max(su, ans)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
score = []
for p in p_list:
    score.append((p + 1) / 2)

max_score = 0
flag = 0
total_score = 0
for i in range(n):
    if i < k - 1:
        total_score += score[i]
    else:
        total_score += score[i]
        max_score = max(max_score, total_score)
        total_score -= score[i - k + 1]
print(max_score)

Submission status: Accepted

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

print((maxval+k)/2)

Submission status: Accepted

Solution code:
#確率は(p_i+1)/2
N, K=(int(i) for i in input().split())
P=[int(i) for i in input().split()]

Q=[(P[i]+1)/2 for i in range(len(P))]
R=[0]*(len(Q)+1)
for i in range(1,len(R)):
    R[i] = R[i-1] + Q[i-1]
maxp=0
for i in range(N-K+1):
        maxp=max((R[i+K]-R[i]), maxp)
print(maxp)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
max_l = 0
point = sum(p[:K])
index = 0

for i in range(1,N-K+1):
  point -= (p[i-1] - p[i+K-1])
  if point > max_l:
    max_l = point
    index = i
print(sum([(n+1)/2 for n in p[index:index+K]]))

Submission status: Accepted

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

num=sum(p[:k])
tot=[num]
t_append=tot.append
for i in range(n-k):
  tmp=p[i+k]-p[i]
  num+=tmp
  t_append(num)
#print(tot)
print(max(tot)/2)

Submission status: Accepted

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

Submission status: Accepted

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

sum_ex = 0

for i in range(k):
    sum_ex += p_ex[i]

sum_ex_prev = sum_ex
for i in range(n - k):
    sum_ex_tmp = sum_ex_prev
    sum_ex_tmp -= p_ex[i]
    sum_ex_tmp += p_ex[i + k]
    sum_ex = max(sum_ex, sum_ex_tmp)
    sum_ex_prev = sum_ex_tmp

print(sum_ex)

Submission status: Accepted

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

Submission status: Accepted

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

E = [(i + 1)/2 for i in p]
S = sum(E[0:K])
ans = S
for i in range(1, N - K + 1):
    S += E[i+K-1] - E[i-1]
    if ans < S:
        ans = S
print(ans)

Submission status: Accepted

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	N, K = list(map(int, input().split()))
	p = list(map(int, input().split()))
	ans = sum(p[:K])
	car = ans
	for i in range(N-K):
		car = car + p[i+K] - p[i]
		ans = max(ans, car)
	print((ans + K) / 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

expect = [(p[i]+1)/2 for i in range(N)]

max_sum = sum(expect[:K])
new_sum = sum(expect[:K])
for i in range(0, N-K):
    new_sum += expect[i+K] - expect[i]
    if max_sum < new_sum:
        max_sum = new_sum

print(max_sum)

Submission status: Accepted

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

Submission status: Accepted

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

a=[0]*N

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

sums=[0]*(N+1)

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

mx=0
for i in range(N-K+1):
    mx=max(mx,sums[i+K]-sums[i])

print(mx)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

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

s_max = sum(P[:K])

s = s_max
for i in range(K, N):
    s = s + P[i] - P[i - K]
    s_max = max(s_max, s)

print((s_max + K)  / 2)

Submission status: Accepted

Solution code:
N, K = [int(s) for s in input().split()]
A = [int(s) for s in input().split()]
def get_expectation(n):
  return n*(2+n-1)/2/n
A = [get_expectation(i) for i in A]
maximum = sum([A[i] for i in range(K)])
tmp = maximum
for i in range(N-K):
  diff = A[i+K]-A[i]
  if tmp+diff >= maximum:
    maximum = tmp+diff
  tmp = tmp+diff
print(maximum)

Submission status: Accepted

Solution code:
import sys
from collections import deque
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
P = [int(x) for x in input().strip().split()]
q = deque([])
cur = 0
ans = 0
for i, p in enumerate(P):
    e = (1+p) / 2
    q.append(e)
    cur += e
    if i >= K-1:
        ans = max(ans, cur)
        e_ = q.popleft()
        cur -= e_
print(ans)

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
l = [(int(x)+1)/2 for x in input().split()]
t = sum(l[:K])
ans = t
for i in range(N-K):
  t = t - l[i] + l[K+i]
  ans = max(ans, t)
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
C = [ 0 for _ in range(N+1) ]
C[0] = 0
for i in range(1,N+1):
  C[i] = p[i-1] + C[i-1]
ans = 0
for i in range(0,N-K+1):
  ans = max( C[i+K]-C[i], ans )
print(ans)

Submission status: Accepted

Solution code:
#400
N,K = map(int,input().split())
p = list(map(int,input().split()))
q = [0 for _ in range(N)]

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

S = sum(q[0:K])
Smax = S
for i in range(N-K):
    S = S - q[i] + q[K+i]
    if S > Smax:
        Smax = S

print(Smax)

Submission status: Accepted

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

Submission status: Accepted

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

ans_index = 0
total = sum(P[0:K])
prev = total
for i in range(N-K):
    tmp = prev + P[i+K] - P[i]
    if tmp > total:
        total = tmp
    prev = tmp

print((total + K) * 0.5)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
nums = [int(i) for i in input().split()]
# n, k = 10, 4
# nums = [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]

expected_values = [num * (num + 1) / 2 / num for num in nums]

accums = [0]
for e in expected_values:
    accums.append(accums[-1] + e)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    total = sum(A[0:K])
    total_max = total
    for i in range(0, N-K):
        total -= A[i]
        total += A[i+K]
        total_max = max(total, total_max)

    print((total_max+K)/2)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

window = [sum(ps[:k])]
for i in range(n-k):
  n = window[i]
  m = n - ps[i] + ps[i+k]
  window.append(m)


print((max(window)-1)*0.5+1+0.5*(k-1))

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p_acc = tuple(accumulate(p))
    p_max = p_acc[k-1]
    if n == k:
        print((p_acc[-1]+k)/2)
        return
    for i in range(n-k):
        p_max = max(p_acc[i+k]-p_acc[i], p_max)
    print((p_max+k)/2)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
N, K = map(int,input().split())
P = list(map(int,input().split()))
P = [(p+1)/2 for p in P]
mx = sum(P[:K])
sm = sum(P[:K])
for i in range(N-K):
    sm = sm - P[i] + P[K+i]
    mx = max(mx,sm)
print (mx)

Submission status: Accepted

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

Submission status: Accepted

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