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()))
Exception_p=[]
for i in range(N):
    Exception_p.append((1+p[i])/2)
sum_Exception=[]
sum=0
for k in range(K):
    sum=(p[k]+1)/2+sum
sum_Exception.append(sum)
for i in range(N-K):
    sum=sum_Exception[i]-p[i]/2+p[i+K]/2
    sum_Exception.append(sum)
list.sort(sum_Exception)    
print(sum_Exception.pop(-1))

Submission status: Accepted

Solution code:
import numpy as np
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[]
for i in p:
  l.append(i+1)
t=np.cumsum(np.array(l),dtype=int)
ans=t[k-1]
for j in range(n-k):
  ans=max(ans,t[j+k]-t[j])
print(ans/2)

Submission status: Accepted

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

result = []
sub_total = sum(p[:k])
result.append(sub_total)

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

print(max(result))

Submission status: Accepted

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

result = []
sub_total = sum(p[0:K])
result.append(sub_total)

for i in range(1, N-K+1):
    sub_total = sub_total - p[i-1] + p[i+K-1]
    result.append(sub_total)

print(max(result))

Submission status: Accepted

Solution code:
def main():
  N, K = (int(x) for x in input().split())
  p = [(int(x)+1)/2 for x in input().split()]
  wa = [0] * (N + 1)
  for i in range(1, N + 1):
    wa[i] = wa[i-1] + p[i-1]
  ret = 0
  for i in range(N-K+1):
    ret = max(ret, wa[K+i]-wa[i])
  print(ret)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

ranges = 0
temp = 0
for i in range(n - k + 1):
    if ranges == 0:
        ranges = sum(p[:k])
        temp = ranges
    else:
        temp = temp - p[i - 1] + p[i - 1 + k]
        if temp > ranges:
            ranges = temp

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

Submission status: Accepted

Solution code:
import math

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

mx = 0
cs = 0
for i in range(k):
    cs += pL[i]
    mx = cs
for i in range(1, len(pL) - k + 1):
    cs = cs - pL[i - 1] + pL[i + k - 1]
    mx = max(mx, cs)
print((mx + k) / 2)

Submission status: Accepted

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

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

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

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


main()

Submission status: Accepted

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

# calc cumsum
C    = list()
cumsum = 0
for ii in range( len(P) ):
    E = (1+P[ii])/2
    C.append( cumsum + E )
    cumsum += E

ans = 0.0
if( N==K ):
    ans = C[-1]
for ii in range( K, N ):
    E = C[ii] - C[ii-K]
    if( ans < E ):
        ans = E

# output        
print( ans )

Submission status: Accepted

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

Submission status: Accepted

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

cumu=[0]
for i in P:
    cumu.append(cumu[-1]+i+1)

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

print(ans/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = [int(p) for p in input().split()]
P_cum = [0] * N
P_cum[0] = P[0]
for i in range(1, len(P)):
    P_cum[i] = P_cum[i - 1] + P[i]

me = 0
for i in range(N - K + 1):
    if i >= 1:
        e = (P_cum[i + K - 1] - P_cum[i - 1] + K) / 2
    else:
        e = (P_cum[i + K - 1] + K) / 2
    me = max(e, me)

print(me)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
def exp(x):
    return (x+1)*(1/2)
p2=[]
for i in range(n):
    p2.append(exp(p[i]))
sum=0
for i in range(k):
    sum+=p2[i]
max=sum
for j in range(n-k):
    sum-=p2[j]
    sum+=p2[j+k]
    if sum>max:
        max=sum
print(max)

Submission status: Accepted

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

sc=list(map(int,input().split()))
c=[]
t=[]

for i in range(n):
  c.append((1+sc[i])/2)
t.append(0.0)
for i in range(n):
  t.append(c[i]+t[i])
total = 0
for i in range(n-k+1):
  #print(t[i+k] - t[i])
  if total < t[i+k] - t[i]:
    total = t[i+k] - t[i]
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

# N = 10
# K = 4
# PRR = [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]
#
# N = 5
# K = 3
# PRR = [1, 2, 2, 4, 5]

def calculate(n, k, prr):

    sumarr = []
    for i in range(n):
        if len(sumarr) == 0:
            sumarr.append(prr[0])
        else:
            sumarr.append(sumarr[-1] + prr[i])

    maxSum = []

    for i in range(k-1,n):

        if i - k < 0:
            sss = sumarr[i] - 0
        else:
            sss = sumarr[i] - sumarr[i - k]
        maxSum.append(sss)

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


calculate(N, K, PRR)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0

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

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

Submission status: Accepted

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

kouho=0
lis=[0]*n
lis[0]=(1+p[0])/2
for i in range(0,n):
  if i>=1:
    lis[i]=lis[i-1]+(1+p[i])/2
  if i==k-1:
    kouho=lis[i]
  if i>k:
    if lis[i]-lis[i-k]>kouho:
      kouho=lis[i]-lis[i-k]
print(kouho)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, K = rl()
P = rl()

sums = [0]
s = 0
for i in range(N):
	s += P[i]
	sums.append(s)
max_ksum = 0
max_i = -1
for i in range(N-K+1):
	ksum = sums[i+K]-sums[i]
	if max_ksum < ksum:
		max_ksum = ksum
		max_i = i

ans = 0
for i in range(max_i, max_i+K):
	ans += P[i]+1
print(ans/2)

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
ans = tmp = np.sum((p[0:K]+1)/2)

for n in range(1, N-K+1):
	last = (p[n-1]+1)/2
	next = (p[n+K-1]+1)/2
	tmp = tmp - last + next
	if ans < tmp:
		ans = tmp

print(ans)

Submission status: Accepted

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

N, K = map(int, input().split())
p = list(map(int, input().split()))
E = [0]*K
max = 0
for i in range(K):
    E[i%K] = (1+p[i])/2
    max += E[i%K]
tmp_E = max
for j in range(K, N):
    tmp_E -= E[j%K]
    E[j%K] = (1+p[j])/2
    tmp_E += E[j%K]
    if max < tmp_E:
        max = tmp_E
print(max)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

d = [0] * n

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

x=r=sum(d[:k])
# print(d)

for i in range(1,n-k+1):
    # r=max(r,sum(d[i:i+k]))
    x=x-d[i-1]+d[i+k-1]
    r=max(r,x)
    # print(r,i)

print(r)

Submission status: Accepted

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

d = []

for v in p:
    d.append((1+v)/2)

x=r=sum(d[:k])
# print(d)

for i in range(1,n-k+1):
    # r=max(r,sum(d[i:i+k]))
    x=x-d[i-1]+d[i+k-1]
    r=max(r,x)
    # print(r,i)

print(r)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
def expect(a):
  return 0.5 * (a+1)

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

r = [total]

for j in range(n-k):
  total = total-expect(p[j])+expect(p[j+k])
  r.append(total)

print(max(r))

Submission status: Accepted

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

S = sum(p[:K])
maxS = S
for i in range(1, N - K + 1):
    S = S - p[i - 1] + p[i + K - 1]
    maxS = max(maxS, S)

print((K + maxS) / 2)

Submission status: Accepted

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

T = [0] * (N+1)

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

ans = 0
for j in range(K, N+1):
  ans = max(ans, T[j]-T[j-K])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans =  sum(nums[:k])
pre_sum = ans

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
summation=[0,A[0]]
for i in range(1,N):
  summation.append(summation[i]+A[i])

maxvalue=summation[K]
for i in range(1,1+N-K):
  maxvalue=max(maxvalue,summation[i+K]-summation[i])
print((maxvalue+K)/2)

Submission status: Accepted

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

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


cnt=0
for i in range(len(a)-1):
    cnt=max(cnt,a[i+1]-a[i-k+1])

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC154D
def main():
    import sys
    N, K = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    L =[0 for _ in range(N)]
    #期待値 (初項+末項)/2
    for i in range(N):
        L[i]=(1 +P[i])/2
    #print(L)
    #累積和
    for i in range(N-1):
        L[i+1] +=L[i]
    #print(L)
    ans = L[K-1]
    for i in range(N-K):
        s = L[i+K]-L[i]
        if ans < s:
            ans = s
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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


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

tmp = sum(map(E, P[:K]))
res = tmp

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

print(res)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

  total = sum(p[:K])
  #print(0, total)

  max_total = total
  max_start_i = 0

  for i in range(1, N-K+1):
    total = total-p[i-1]+p[i-1+K]
    #print(i, total)
    if total > max_total:
      max_total = total
      max_start_i = i

  #print(max_start_i, max_total)

  print(sum([(1+p)/2. for p in p[max_start_i:max_start_i+K]]))

main()

Submission status: Accepted

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

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

### K個合算した数値の配列
cumsum = []
cumsum_temp = 0
for i in range(len(p) - K + 1):
    if i == 0:
        cumsum_temp = sum(expected_value[:K])
    else:
        cumsum_temp = cumsum_temp - expected_value[i - 1] + expected_value[i + K - 1]
    cumsum.append(cumsum_temp)
# print(f"N:{N} K:{K} expected_value:{expected_value} cumsum:{cumsum}")

print(max(cumsum))

Submission status: Accepted

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

s=[0]*(n+1)

for i in range(1,n+1):
  s[i]=s[i-1]+1/2*(p[i-1]+1)
res=s[k]
for i in range(n-k+1):
  res = max(res,s[i+k]-s[i])
print(res)

Submission status: Accepted

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

meanList = []

for a in p:
    meanList.append((a + 1) / 2)

sums = [0]

for a in meanList:
    sums.append(sums[-1] + a)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
def f(n, k, p):
    p = [(i+1)/2 for i in p]
    sums = sum(p[:k])
    mx = sums
    for i in range(k, n):
        sums = sums - p[i - k] + p[i]
        # print(f"sums = {sums}")
        if sums > mx:
            mx = sums
    print(mx)

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

Submission status: Accepted

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


ans = 0
for i in range(len(P)-K+1):
    if i == 0:
        c = sum(P[:K])
    else:
        c = c + P[i+K-1] - P[i-1]
    if c > ans:
        ans = c


print((ans+K)/2)

Submission status: Accepted

Solution code:
#定数
#1≦k≦n≦2*10^5
n , k = map(int, input().split())
#1≦P[i]≦10^3
#O(n)
P = list(map(int, input().split()))

#サイコロの目が1~numの期待値を求める関数
#O(1)
def dice_expectations(num:int)->float:
    return (num+1) / 2

#O(n)
E = list(map(dice_expectations, P)) #Expectations

#k個ずつ
tmp = sum(E[0:k])
ans = 0
#O(n-k+1)
for i in range(n-k+1):
    if tmp > ans:
        ans = tmp
    else:
        pass
    if i != n-k:
        tmp -= E[i]     #先頭のサイコロを取り除き
        tmp += E[k+i]   #次のサイコロを追加する
    else:
        pass

print(ans)  #O(n)

Submission status: Accepted

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

Submission status: Accepted

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

psum = [0]
for i in range(n):
    psum.append(psum[-1] + p[i])

ans = [psum[k+i] - psum[i] for i in range(n-k+1)]
print((max(ans)+k) / 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
*p, = map(int, input().split())
Ep = [(x + 1) / 2 for x in p]
S = [0 for _ in range(N+1)]

for i in range(N):
  S[i+1] = S[i] + Ep[i]
m = 0
for i in range(N):
  if i + K > N:
    break
  m = max(m, S[i+K]-S[i])
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for i in range(1, K + 1):
    ans += E[i]

cur = ans
for i in range(1, N - K + 1):
    cur = cur - E[i] + E[i + K]
    if cur > ans:
        ans = cur
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
def P(x):
    return (x+1)/2
a=0
y=0
for i in range(N):
    y+=P(p[i])#区間内の期待値の和
    if i>=K:
        y-=P(p[i-K])
    if a<y:
        a=y
print(a)

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split())
p=list(map(int,input().split()))
E=[]
for i in range(N):
  E.append((1+p[i])/2)
S=np.cumsum(E)
max=0
if N!=K:
  for i in range(N-K+1):
    if S[i+K-1]-S[i-1]>max:
       max=S[i+K-1]-S[i-1]
  print(max)
else:
  print(sum(E))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(float, input().split()))
tmp = sum(p[:k])
ans = 0

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

ans = max(ans, tmp)
print((ans + k) / 2)

Submission status: Accepted

Solution code:
dice_num, use_num = [int(n) for n in input().rstrip().split()]

points = [int(n) for n in input().rstrip().split()]

sum = sum(points[:use_num])
max_sum = sum
    
for i in range(dice_num-use_num):
    next = sum + points[i+use_num] - points[i]
    max_sum = max(next,max_sum)
    sum = next
    
max_sum_expectation = (use_num + max_sum)/2

print(max_sum_expectation)

Submission status: Accepted

Solution code:
# ABC154 -virtual
# A
if False:
    S,T=input().split()
    A,B=map(int,input().split())
    U=input()
    if U==S:
        A-=1
    else:
        B-=1
    print(A,B)
# B
if False: print('x'*len(input()))
# C
if False:
    N=int(input())
    A=[int(i) for i in input().split()]
    print('YES' if len(A)==len(set(A)) else 'NO')
# D
if True:
    N,K=map(int,input().split())
    P=[int(i) for i in input().split()]
    E=[(p+1)/2 for p in P]
    # print(E)
    ans=tmp=sum(E[0:K])
    l,r=1,K
    while r<len(E):
        # print(l,r)
        tmp=tmp-E[l-1]+E[r]
        ans=max(ans,tmp)
        # print(ans)
        l+=1
        r+=1
    print(ans)
        
# E
# F

Submission status: Accepted

Solution code:
[N,K]=[int(item)for item in input().split()]
p = [int(item) for item in input().split()]
su = sum(p[0:K])
maxsu=su
ind=0
for i in range(0, N-K):
    su=su - p[i] + p[i + K ]
    if su > maxsu:
        ind = i+1
        maxsu=su
#print("{},{}".format(su,maxsu))
#print(p[ind:ind+K])
#print([n*(n+1)/(2*n) for n in p[ind:ind+K]])
print(sum([n*(n+1)/(2*n) for n in p[ind:ind+K]]))

Submission status: Accepted

Solution code:
import math
import sys
N,K=map(int,input().split())
pi=list(map(int,input().split()))
dice=[0]*N
for i in range(N):
    dice[i]=pi[i]*(pi[i]+1)/2/(pi[i])
#print(dice)
a = sum(dice[0:K])
max=a
for i in range(1,N-K+1):
    a=a-dice[i-1]+dice[K+i-1]
    #print(dice[i:i+K])
    if a>max:
        max=a

print(max)

Submission status: Accepted

Solution code:
N, K =map(int, input().split())
P = list(map(float, input().split()))
EXP = [0]*N
for i in range(N):
    if P[i] == 1:
        EXP[i] = 1
    else:
        EXP[i] = (P[i]+1)/2
ADD = [0]*N
for i in range(N):
    if i == 0:
        ADD[i] = EXP[i]
    else:
        ADD[i] = ADD[i-1] + EXP[i]
SUM = [0]*N
for i in range(K-1, N):
    if i == K-1:
        SUM[i] = ADD[K-1]
    else:
        SUM[i] = ADD[i] - ADD[i-K]
print(max(SUM))

Submission status: Accepted

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

for j in range(N-K+1):
  ans.append(hope[j+K]-hope[j])
print(max(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 04:56:52 2020

@author: Kanaru Sato
"""

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

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


Max = -100000
for i in range(n-k+1):
    e = sumlist[i+k]-sumlist[i]
    if Max < e:
        Max = e

print((Max+k)/2)

Submission status: Accepted

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

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

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
P = np.array(lr())
P = np.hstack([[0], P+1])
Pcum = P.cumsum()
result = Pcum[K:] - Pcum[:-K]
answer = result.max()
print(answer / 2)

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
P = np.array([0] + lr(), np.float64)
P = (P+1) / 2
Pcum = P.cumsum()
expectation = Pcum[K:] - Pcum[:-K]
answer = expectation.max()
print(answer)

Submission status: Accepted

Solution code:
"""
int(input())
map(int,input().split())
list(map(int,input().split()))

"""

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append((a[i]+1)/2)
c=[]
s=sum(b[0:k])
for i in range(k-1,n):
    c.append(s)
    if(i==n-1):
        break
    s=s+b[i+1]-b[i-k+1]

print(max(c))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
List=list(map(int,input().split()))
t=-1
S=[0]
for i in range(a):
    S+=[S[i]+List[i]]
t=-1
for i in range(a-b+1):
    if S[i+b]-S[i]>t:
        t=S[i+b]-S[i]
print((t+b)/2)

Submission status: Accepted

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

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

else:
  for i in range(n-k):
    if result < rsum[i+k] - rsum[i]:
      result = rsum[i+k] - rsum[i]

print(result)

Submission status: Accepted

Solution code:
from collections import deque 
n,k = map(int,input().split())
p = list(map(int,input().split()))
q = deque()
s = 0
m = 0
ans = 0
for i in range(len(p)):
  p[i]+=1
for j in range(n):
  s+=p[j]
  q.append(p[j])
  if len(q)>k:
    s-=q.popleft()
  if len(q)==k:
    m = max(m,s)
ans = m
ans/=2
print(ans)

Submission status: Accepted

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

rsum  = [0]*n
for i in range(n):
    rsum[i] = (p[i]+1) / 2
    if(i != 0):
        rsum[i] = rsum[i] + rsum[i-1]

result = 0
if(n == k):
    result = rsum[n-1]
else:
    for i in range(n-k):
        if(result < rsum[i+k] - rsum[i]):
            result = rsum[i+k] - rsum[i]
print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

n,k = l_in()
P = list(map(lambda p: (1+p)/2, l_in()))

res = sum(P[:k])
current = res

for i in range(k, n):
    current -= P[i-k]
    current += P[i]
    res = max(res, current)

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_line=input().split(" ")
N,K=int(input_line[0]),int(input_line[1])
P=input().split(" ")
cumsum=[0]
tol=0
for i in range(N):
    P[i]=(int(P[i])+1)/2
    tol=tol+P[i]
    cumsum.append(tol)
    
k_sum=[]

for i in range(N-K+1):
  k_sum.append(cumsum[i+K]-cumsum[i])  

ans=max(k_sum)
print(ans)

Submission status: Accepted

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

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

    e = map(expectation, p)

    def accumulation(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *acc, = accumulation(e)

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

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

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

def main():
  n,k = input_list()
  p = input_list()
  kakus = [0]*(n+1)
  for i in range(1, n+1):
    kaku = (1+p[i-1])/2
    pre = kakus[i-1]
    kakus[i] = kaku+pre
  ans = []
  for i in range(len(p)-k+1):
    ans.append(kakus[i+k]-kakus[i])
  print(max(ans))
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Accepted

Solution code:
def main():  
  import sys
  input = sys.stdin.readline
  import numpy as np #pypy不可
  n,k = map(int,input().split())
  p = np.array(input().split(),np.int32)
  np.cumsum(p,out=p)
  chk = p[k-1]
  for i in range(n-k):
    c = p[i+k]-p[i]
    chk = max(c,chk)
  print((chk+k)/2)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans/=2
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

a = 0
for i in range(N - K + 1):
  if i == 0:
    b = sum(p[0:K])
  else:
    b = b - p[i-1] + p[i + K - 1]
  
  if b > a:
    a = b
    f = i

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

print(ans)