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:
from itertools import accumulate

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

new_p = []
temp = []
for i in p:
    new_p.append(((i * (i + 1)) / 2) / i)
q = [0] + new_p
q = list(accumulate(q))

for i in range(len(q) - k):
    temp.append(q[i + k] - q[i])
print(max(temp))

Submission status: Accepted

Solution code:
import queue
import copy
import math
from collections import deque
import bisect

# 2つの入力を空白で分割し、数値化
n, k = map(int, input().split())

# 空白区切りの数値をリスト化
pn = list(map(int, input().split()))

expects = []
max_e = 0
prev_e = 0

for p, i in zip(pn, range(0, n)):
    e = (((1 + p) * p) // 2) / p
    expects.append(e)
    if i + 1 == k:
        max_e = sum(expects)
        prev_e = max_e
    elif i + 1 > k:
        current_e = prev_e + expects[-1] - expects[i-k]
        max_e = max(max_e, current_e)
        prev_e = current_e
    else:
        continue

print(max_e)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a = list(map(int,input().split()))

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

e = [(pi+1)/2 for pi in p]

ret2 = []
b = 0.0
for j in range(k):
        b += e[j]
ret2.append(b)

for i in range(n-k):
        ret2.append(ret2[i] - e[i] + e[i+k])

ret=ret2

ret.sort()
print(ret[n-k])

Submission status: Accepted

Solution code:
import numpy as np

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

last_value = 0
l = [0]

for head, tail in zip(p, p[K:]):
    now = tail - head + last_value
    l.append(now)
    last_value = now
max_index = np.argmax(l)
max_sum = sum(p[max_index : max_index + K])
print((K + max_sum) / 2)

Submission status: Accepted

Solution code:
from itertools import accumulate

n,k = map(int, input().split())
p = list(map(int, input().split()))
acc = list(accumulate([i for i in range(max(p)+1)]))
ap = [0] + list(accumulate(p))
mx = 0
pos = 0
for i in range(n-k+1):
    if mx < ap[i+k] - ap[i]:
        mx = ap[i+k] - ap[i]
        pos = i
ans = 0
for i in range(pos,pos+k):
    ans += acc[p[i]] / p[i]
print('{:.10f}'.format(ans))

Submission status: Accepted

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

def calc(n):
  return sum(range(1, n + 1)) / n

sums = [0]
s = 0
for i in range(N):
  s += calc(P[i])
  sums.append(s)

max_value = -1
max_index = -1

# print(sums)
for i in range(N - K + 1):
  s = sums[i+K] - sums[i]
  # print(i)
  # print(i+K)
  max_value = max(max_value, s)
  if max_value == s:
    max_index = i

print(max_value)
# print(sum([calc(P[i]) for i in range(max_index, max_index + K)]))

Submission status: Accepted

Solution code:
def kitaichi(a):
    return ((1+a)*a/2)/a

n, k = map(int, input().split())
p = [int(_) for _ in input().split()]
dp = [0] * n
dp[0] = p[0]
cnt = 1

maxi = 0
idx = 0

for i in range(1, n):
    if cnt < k:
        dp[i] = p[i] + dp[i-1]
        cnt += 1
    else:
        dp[i] = p[i] + dp[i-1] - p[i-k]
    if maxi < dp[i]:
        maxi = dp[i]
        idx = i

ans = 0
for i in range(idx-k+1, idx+1):
    ans += kitaichi(p[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = sum(p[:k])
ans_tmp = copy.copy(ans)

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


print((ans+k)/2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc154/tasks/abc154_d
import numpy as np
N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
p = (p + 1) / 2
cumsum = np.cumsum(np.array(p))
tmp = np.pad(cumsum[:-K], [K, 0], 'constant')
print((cumsum - tmp).max())

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.int64)
Pcum[1:] = P.cumsum()

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

Submission status: Accepted

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

cnt=0
ans=0
buf=0
buf_2=0
q=deque([])
cnt=0
for i in range(N):
    cnt+=1
    buf=P[i]*(P[i]+1)//2/P[i]
    q.append(buf)
    buf_2+=buf
    if cnt>=K:
        if ans<buf_2:
            ans=buf_2
        buf_2-=q.popleft()
    # if len(q)==K:
    #     if sum(q)>ans:
    #         ans=sum(q)
    #     q.popleft()
print(ans)

Submission status: Accepted

Solution code:
#D - Dice in Line
N,K = map(int,input().split())
p = list(map(int, input().split()))
S = [0]*N
s = 0
s_t = 0
S[0] = (1+p[0])/2

if N == 1:
    print(S[0])
    exit()
else:
    pass

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

if N == K:
    print(S[N-1])
    exit()
else:
    pass

for j in range(N-K):
    s_t = S[j+K]-S[j]
    if s_t >= s:
        s = s_t
    else:
        pass

print(s)

Submission status: Accepted

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

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

#print(p)
#print(s)
maxValue = -100100100
anker = -99

for i in range(n-k+1) :
    if maxValue < s[i+k] - s[i] :
        maxValue = s[i+k] - s[i]
        anker = i
ans = 0
for i in range(anker+1, anker+k+1) :
    ans += p[i]
    #print(ans)

print(ans)

Submission status: Accepted

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

def main():
  n, k = map(int, input().strip().split())
  Ps   = numpy.array(input().strip().split(), dtype=int)
  Es   = numpy.zeros(n+1)
  max = -1
  for i, P in enumerate(Ps):
    Es[i] = 0.5 * (P+1) + Es[i-1]
  max = -1
  for i in range(n-k+1):
    x = Es[i+k-1] - Es[i-1]
    if max < x:
      max = x
  print(max)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
listp = tuple(map(int, input().split()))
bc =sum(listp[0:K])
b = sum(listp[0:K])
for n in range(1,N-K+1):
    b = b - listp[n-1]+listp[n+K-1]
    
    if b > bc:
        bc = b
    else:
        pass    
    #print(b)    
print((bc+K)/2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

#a = list(map(int, input().split()))

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

sums = [0 for i in range(n+1)]

for i in range(n):
    sums[i+1] = sums[i]+a[i]

mat = -1
for i in range(n-k+1):
    nowsum = -sums[i] + sums[i+k]
    #print(nowsum)
    if(nowsum>mat):
        mat = nowsum

print(mat/2+k/2)

Submission status: Accepted

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

e = []
for i in p:
    e.append(1+i)

l = 0
s = sum(e[l:k-1])
t = sum(e[l:k-1])
for i in range(n-k):
    tmp = t + e[i+k] - e[i]
    t = t + e[i+k] - e[i]
    if tmp > s:
        s = tmp
        l = i + 1

print(sum(e[l:l+k])/2)

Submission status: Accepted

Solution code:
import numpy as np

def dice():
    n, k = map(int, input().split())
    p = np.asarray(list(map(int, input().split())))
    pp = np.zeros(n)
    for i in range(n):
      pp[i] = p[i]*(p[i]+1)/(2*p[i])
    ans = sum(pp[0:k]) 
    tmp = sum(pp[0:k])
    for i in range(1, n-k+1):
        tmp = tmp - pp[i-1] + pp[i+k-1]
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == '__main__':
    dice()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
ans=sum(P[:K])/2+0.5*K
A,S=[0]*N,[0]*N
A[0]=S[0]=P[0]
for i in range(N-1):
    A[i+1]=P[i+1]
    S[i+1]=S[i]+A[i+1]

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
saidai = 0
wa =[None]*n
wa_2 = 0
gokei = 0
for i in range(n):
    gokei += p[i]
    wa[i] = gokei
saidai = wa[k-1]
for j in range(n-k):
    wa_2 = wa[j+k]-wa[j]
    if wa_2 > saidai:
        saidai = wa_2
kitai = (1/2)*(k+saidai)
print(str(kitai))

Submission status: Accepted

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

Submission status: Accepted

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

sum_k = sum(P[:k])
temp_sum_k = sum_k 

for i in range(n-k):
  temp_sum_k = temp_sum_k+P[i+k]-P[i]
  if sum_k < temp_sum_k:
    sum_k = temp_sum_k

print((sum_k+k)/2)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
result = 0
p_t = [0]
for i in range(N):
    p_t.append(p[i]+p_t[i])
ans = p_t[K] - p_t[0]

for i in range(N-K):
    tmp = p_t[i+1+K] - p_t[i+1]
    if ans < tmp:
        ans = tmp
print((ans+K)/2)

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, k, p):
    acum_E = [0]
    sum_E = 0
    for i, p_i in enumerate(p):
        sum_E += (1.0 + p_i)/2 
        acum_E.append(sum_E)
    # pprint(acum_E)
    
    ans = 0
    for i in range(n - k + 1):
        # print(i+k, i)
        ans = max(ans, acum_E[i + k] - acum_E[i])
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)

Submission status: Accepted

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

for p_item in p:
  B.append(float((p_item+1)/2))
  
Max = sum(B[:K])
tmp = sum(B[:K])

for i in range(len(B)-K):
    tmp = tmp - B[i] + B[i+K]
    if Max < tmp:
      Max = tmp

print(Max)

Submission status: Accepted

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

tmp = 0
for i in range(n):
    tmp += e[i]
    if i >= k:
        tmp -= e[i - k]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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


print(anss)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

import itertools as its
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def comp(p):#期待値
    return ((p+1)/2)


#input
n,k=(pin())
S=list(pin())
debug(S)
s=([comp(S[_]) for _ in range(n)])
ans=0
#print(s)
x=list(its.accumulate(s))
#print(list(its.accumulate(s)))
#default
for a in range(k):
    ans=x[k-1]
#print("*",ans,0,k-1)
temp=0.0
for i in range(1,n-k+1):
    
    ans=max(ans,x[k+i-1]-x[i-1])
print(ans)
#print(["NO","YES"][1-cond])

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = [(int(i)+1.0)/2.0 for i in input().split()]
ans = 0
for i in range(k):
    ans += p[i]
tmp1 = ans
for i in range(k, n):
    tmp2 = (tmp1 - p[i-k])+p[i]
    ans = max(ans, tmp2)
    tmp1 = tmp2
print('{:.12f}'.format(ans))

Submission status: Accepted

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

ls_mu = []
for i in range(n):
    mu = (p[i]+1)/2
    ls_mu.append(mu)
# print(ls_mu)
m = 0
M = 0
for i in range(n-k+1):
    if i==0:
        for j in range(k):
            m += ls_mu[j]
        M += m
    else:
        l = ls_mu[i-1]
        r = ls_mu[i+k-1]
        m = m - l + r
        M = max(m,M)

print(M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
X=0
for k in range(K):
	X+=P[k]
Y=X
for n in range(1,N-K+1):
	Y=Y+P[n+K-1]-P[n-1]
	X=max(X,Y)
print((X+K)/2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
tmp = sum(P[:K])
high = tmp
e = 0
for i in range(1, N-K+1):
    tmp -= P[i-1]
    tmp += P[i+K-1]
    if tmp > high:
        high = tmp
        e = i
exp = 0
for p in P[e:e+K]:
    exp += sum(range(1,p+1)) / p

print(exp)

Submission status: Accepted

Solution code:
import numpy as np

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

s = (K+ np.sum(P[:K]))/2
ans = s
for i in range(1,N-K+1):
    s = s - P[i-1]/2 + P[i+K-1]/2
    if s > ans:
        ans = s
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

if N == K:
    myans = 0
    for n in range(N):
        myans += (mylist[n]+1)/2
    print(myans)
    sys.exit()

if K == 1:
    print((1+max(mylist))/2)
    sys.exit()
    
dp = [0 for n in range(N)]

for i in range(K):
    dp[i] = (mylist[i]+1)/2
dp[K-1] = sum(dp[0:K])

myans = -999999999
for n in range(K,N):
    dp[n] = (mylist[n]+1)/2 + dp[n-1] - (mylist[n-K]+1)/2 
    if myans < dp[n]:
        myans = dp[n]

        
print(myans)

Submission status: Accepted

Solution code:
import math
import itertools
#n = int(input())
#n, d = list(input().split())
n, k= list(map(int, input().split()))
p = list(map(int, input().split()))
point = []
rui = []

def s(n):
    if(n==1):
        return 1
    else:
        return (n*(n+1))/2


#for は一重まで
for i in range(n):
    point.append(s(p[i])/p[i])
    if i==0:
        rui.append(point[0])
    else:
        rui.append(rui[i-1]+point[i])


m = 0
a = 0
for i in range(n-k+1):
    if i==0:
        a = rui[i+k-1]
    else:
        a = rui[i+k-1]-rui[i-1]
    
   # print(a)
    if a > m:
        m = a



#print(point)
#print(rui)
print(m)

Submission status: Accepted

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

p_cum = []
temp=0
for elm in p:
    temp+=elm
    p_cum.append(temp)

max=0
temp=0
for k in range(N-K+1):
    temp_max = (p_cum[k+K-1]-temp+K)/2.0
    if max < temp_max:
        max=temp_max
    temp=p_cum[k]
print(max)

Submission status: Accepted

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


def calc_mean(p):
    return (p + 1) / 2


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

r = k
cur_value = max_value
for l in range(1, n - k + 1):
    cur_value = cur_value - calc_mean(p[l - 1]) + calc_mean(p[r])
    max_value = max(max_value, cur_value)
    r += 1

print(max_value)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
import numpy as np


def main():
    N, K = map(int, input().split())
    ps = np.array(list(input().split()), dtype=int)
    ps = (ps + 1) / 2

    s_list = [0 for _ in range(N)]

    left = 0
    right = K
    s_list[0] = sum(ps[left:right])

    maximum = s_list[0]

    for i in range(1, N):
        left = ps[i-1]

        p_right = K + i - 1
        if p_right >= N:
            right = 0
        else:
            right = ps[p_right]

        s_list[i] = s_list[i-1] - left + right
        maximum = max(maximum, s_list[i])

    return maximum


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

Submission status: Accepted

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

s = sum(p[:k]) + k
t = s
for a, b in zip(p, p[k:]):
    t = t - a + b
    s = max(s, t)

print(s/2)

Submission status: Accepted

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

MAX = 0
# dp[i] i 番目から i + K - 1 番目までのサイコロの期待値の和
dp = [0] * N
for i in range(N - K + 1):
    if i < 1:
        dp[i] = 0.5 * (sum(p[:K]) + K)
    else:
        dp[i] = dp[i - 1] - 0.5 * p[i - 1] + 0.5 * p[i + K - 1]

    MAX = max(MAX, dp[i])
print(MAX)

Submission status: Accepted

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

#初期
SUM = [0]*N
SUM[0] = sum(P[0:K])

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

EXP_V = (K + max(SUM))/2
print(EXP_V)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
p = list(map(int, input().split()))
m = max(p)
h = [0]*(m+1)
h[1] = 1
for i in range(1,m):
    h[i+1] = h[i]+0.5
ans = sum = 0
for i in range(n):
    if i>=k:
        sum = sum-h[p[i-k]]+h[p[i]]
        if ans<sum: ans=sum
    else:
        sum += h[p[i]]
        if i==k-1: ans=sum
print(ans)

Submission status: Accepted

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

a = sum(p[0:k])
b = a
c = a

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
p = list(map(int, input().split()))
cnt = sum(p[0:k])
tmp = 0
for i in range(k, n):
    if p[i] + tmp - p[i-k] > 0:
        cnt += p[i]-p[i-k]+tmp
        tmp = 0
    else:
        tmp += p[i]-p[i-k]
print((cnt+k)/2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
array = list(map(int, input().split()))

sum = 0
max = 0

for i in range(K):
    sum += array[i]
    max = sum

for i in range(K, N):
    sum += array[i] - array[i - K]
    if sum > max:
        max = sum

E = (max + K) / 2
print(E)

Submission status: Accepted

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

    r = [0]
    for i in range(N):
        r.append(r[i]+p[i])


    ans = 0
    max_i = 0
    max_value = 0
    for i in range(1,N-K+1):
        t = r[i+K]-r[i]
        if max_value < t:
            max_value = t
            max_i = i



    for i in range(max_i, max_i+K):
        if len(p) <= i:
            break
        n = p[i] + 1
        ans += (n*(n-1)//2) / (n-1)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def expect(x):
    return ((x*(x+1))//2) / x

for p in P:
    e.append(expect(p))

ans = sum(e[:K])
tmp = ans
#print(e, e[:K])
for i in range(K, N):
    tmp = tmp - e[i-K] + e[i]
    ans = max(ans, tmp)
    #print(tmp, ans, e[i-K], e[i])

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().rstrip().split(" "))
p = list(map(int,input().rstrip().split(" ")))
karians = K
for i in range(K):
  karians += p[i]
ans = karians
for i in range(N - K):
  karians -= p[i]
  karians += p[i + K]
  if ans < karians:
    ans = karians
print(ans / 2)

Submission status: Accepted

Solution code:
s=[0]
for i in range(1000):
    s.append(s[i]+i+1)
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[0]
for i in range(n):
    l.append(l[i]+p[i])
tmp=0
at=n-k
for i in range(n-k+1):
    if l[i+k]-l[i]>tmp:
        tmp=l[i+k]-l[i]
        at=i
ans=0
for i in range(k):
    ans+=s[p[at+i]]/p[at+i]
print(ans)

Submission status: Accepted

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

m=0

for i in range(0,K):
    m=m+p[i]+1

A=[]
A.append(m)

if N==K:
    print(A[0]/2)
else:
    for i in range(1,N-K+1):
        s=A[i-1]-p[i-1]+p[i+K-1]
        A.append(s)
    print(max(A)/2)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

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

    loop=n-k+1

    ms=0
    bef=0
    for i in range(loop):
        tmp=0
        if i ==0:
            for j in range(k):
                tmp+=p[i+j]/2+1/2
            if tmp > ms:
                ms = tmp
        else:
            tmp=bef
            tmp-=(p[i-1]/2+1/2)
            tmp+=(p[i+k-1]/2+1/2)
            if tmp > ms:
                ms = tmp
        bef=tmp

    print(ms)

    return

resolve()

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

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

P = np.array(P, dtype=float)
E = (P + 1) / 2
cs = E.cumsum()

ans = cs[K - 1]
if K < N:
    ans = max(ans, (cs[K:] - cs[:-K]).max())
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n,m=IA()
a=list(IA())
ans=float(0)

N=int(200005)
s=[int(0) for i in range(N)]

s[1]=a[0]
for i in  range(1,n):
    s[i+1]=s[i]+a[i]
   

    
for i in  range(1,n+1):
   

    if i+m-1>n:break
    #print(s[i+m-1]-s[i-1])
    sum1=(s[i+m-1]-s[i-1]+m)/2

    #print(sum1)
    ans=max(ans,sum1)
    
print("%.12lf"%ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
goukei = 0
ind = 0
kitai = 0

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

list = [goukei]

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

ind = list.index(max(list))

for j in range(ind, ind+k):
    kitai = kitai + (p[j]+1)/2
'''
print(max(list))
print(p)
print(list)
print(ind)
'''
print(kitai)

Submission status: Accepted

Solution code:
from collections import deque

def sum_to(n):
    return (n+1)*int((n/2))+(n%2)*((n+1)/2)

def expected(n):
    return sum_to(n) / n

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

max_sum = 0
cur_sum = 0
select = deque()
c = 0
for i in P:
    e_val = expected(i)
    select.append(e_val)
    cur_sum += e_val
    if len(select) == K:
        if cur_sum > max_sum:
            max_sum = cur_sum
        cur_sum -= select.popleft()

print(max_sum)

Submission status: Accepted

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

Submission status: Accepted

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

e = [0] *n;
ruiseki = [0]*(n+1);

for i in range(n) :
	e[i] = p[i]*(p[i]+1)//2/p[i];
	ruiseki[i+1] = ruiseki[i] + e[i];

ans = 0;
for i in range(n-(k-1)) :
	if ans < ruiseki[i+k] - ruiseki[i] :
		ans = ruiseki[i+k] - ruiseki[i];

print(ans);

Submission status: Accepted

Solution code:
# きりみんちゃんの配信をみてたので期待値は分かる
# 素直にTLEくらったので累積和で加減する
# え これでもだめなの
# あほだった sumしてるし
# 単純にみたら 0.5ずつ増えてるのでそうするか
# 1WA...
# N = 1の場合か？


n, k = map(int, input().split())
arr = list(map(int, input().split()))
table = {}
ans = 0
for i in range(1, 1000 + 1):
    table[i] = (i + 1) * 0.5
if n == 1:
    print(table[arr[0]])
    exit()
lis = [0 for _ in range(n)]
lis[0] = table[arr[0]]
for i in range(n - 1):
    if i + 1 < k:
        lis[i + 1] = lis[i] + table[arr[i + 1]]
    else:
        lis[i + 1] = lis[i] + table[arr[i + 1]] - table[arr[i - k + 1]]
    ans = max(ans, lis[i + 1])
print(ans)

Submission status: Accepted

Solution code:
def main(n,k,p):
    res = 0
    #期待値リスト
    kitai = [0] * n
    ruiseki = [0] * n
    kitai[0] = (p[0] + 1) / 2
    ruiseki[0] = kitai[0]
    if n == 1:
        return kitai[0]
    else:
        for i in range(1, len(p)):
            kitai[i] = (p[i] + 1) / 2
            ruiseki[i] = ruiseki[i-1] + kitai[i]
    for i in range(k-1, len(ruiseki)):
        res = max(res, ruiseki[i] - (ruiseki[i-k] if (i-k) >= 0 else 0))
    return res


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

Submission status: Accepted

Solution code:
hoge = input().split()

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

p_list = list(map(int,input().split()))
  
big = 0
s = [0] * (N+1)
for i in range(N):
  s[i+1] = s[i] + p_list[i]

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

ans = (float(res) / 2) + 0.5 * float(K) 
print(ans)

Submission status: Accepted

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

continuous_sum = (lambda n: (n + 1) * (n // 2) + (0 if n %2 == 0 else n // 2 + 1))
calc_expectedval = (lambda p: continuous_sum(p) / p)
expected_vals = [calc_expectedval(int(x)) for x in input().split()]

prevval = sum(expected_vals[0:0+k])
maxval = prevval
for i in range(n - k):
  candidate = prevval - expected_vals[i] + expected_vals[i + k]
  if candidate > maxval:
    maxval = candidate
  prevval = candidate

print(maxval)

Submission status: Accepted

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

s = sum([p[i] for i in range(K)])
data = [s]
for i in range(N-K):
    s = s-p[i]+p[i+K]
    data.append(s)
print((max(data)+K)/2)

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
arr = np.array([int(_)*(int(_)+1)/(int(_)*2.0) for _ in input().split()])

max = t = sum(arr[0:k])

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

r = 0
for i in range(k):
    r += p[i]
p_.append(r)

for i in range(k, n):
    r += p[i] - p[i-k]
    p_.append(r)

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

Submission status: Accepted

Solution code:
def sums(N):
  return 1 + (N-1) * 0.5

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

exp = [0 for _ in range(N)]
for i in range(0, N):
  exp[i] = sums(Ps[i])

summed = [0 for _ in range(N)]
summed[0] = exp[0]

for i in range(1, N):
  summed[i] = summed[i-1] + exp[i]

max_i=summed[K-1]

for i in range(K, N):
  max_i = max(max_i, summed[i]-summed[i-K])

print(max_i)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
li_p = list(map(int, input().split()))
def kitaichi(a):
  b = 0
  for i in range(1, a+1):
    b += i
  return b/a
li_s = []
for x in li_p:
  li_s.append(kitaichi(x))
ans = []
d = 0
for i in range(k):
  d += li_s[i]
  ans.append(d)
for j in range(k, n):
  d += li_s[j]
  d -= li_s[j-k]
  ans.append(d)
print(max(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

wa = sum(P[:K])
tmp = wa
ind = 0
for i in range(1, N - K+1, 1):
    tmp +=P[i+K-1]
    tmp -= P[i-1]
    if tmp > wa:
        wa = tmp
        ind = i
    else:
        pass

# 期待値を求める
ans = 0

for i in range(ind, ind+K, 1):
    now = P[i]
    ans += (now+1) /2
print("{:.10f}".format(ans))

Submission status: Accepted

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

maxsum = sum(pl[:K])
maxindex = K-1

tmpsum = maxsum
for i in range(K,N):
    tmpsum = tmpsum - pl[i-K] + pl[i]
    if(tmpsum>maxsum):
        maxindex = i
        maxsum = tmpsum

anspl = pl[maxindex-K+1:maxindex+1]
print(sum(map(lambda x:x/2+0.5,anspl)))

Submission status: Accepted

Solution code:
import numpy as np

numlist = list(map(int,input().split()))
N = numlist[0]
K = numlist[1]

demelist = list(map(int,input().split()))
demearray = np.array(demelist)

exparray = (demearray+1)/2

Exp = 0
i = 0
while i < K:
    Exp = Exp + exparray[i]
    i = i + 1

Expmax = Exp

j = 1
while j < N-K+1:
    Exp = Exp - exparray[j-1] + exparray[K+j-1]
    if Exp > Expmax:
        Expmax = Exp
    j = j + 1

print(Expmax)