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 copy import copy
N,K = map(int, input().split())
p=list(map(int, input().split()))
expP = [(1+i)/2 for i in p]
id_H = N-K
id_T = N
minus = sum(expP[:id_H])
minimum = minus
for i in range(id_H):
    minus -= expP[id_H - i -1]
    minus += expP[id_T - i -1]
    if minus < minimum:
        minimum = copy(minus)
ans = sum(expP) - minimum
print(ans)

Submission status: Accepted

Solution code:

def ex_dice(n):
    n = int(n)
    a = n*(n+1) / 2
    return a / n


n, k = list(map(int, input().split()))
dices = list(map(ex_dice, input().split()))
exp = 0
for i in range(k):
    exp += dices[i]

max_val = exp

for i in range(n - k):
    first_val = dices[i]
    next_val = dices[i+k]
    exp = exp + next_val - first_val
    max_val = max(max_val, exp)

print(max_val)

Submission status: Accepted

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

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

    m = 0
    a = 0
    for i in range(1, n-k+1):
        wa -= p[i-1]
        wa += p[i+k-1]
        if m < wa:
            a = i
            m = wa

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

    print(ans)


main()

Submission status: Accepted

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


num=0
S=0
ans=0

for i in range(K):
    num=P[i]
    S=P[i]*(P[i]+1)//2
    ans+=S/num
A=[ans]
for i in range(N-K):
    m=(P[i]*(P[i]+1)//2)/P[i]
    a=(P[i+K]*(P[i+K]+1)//2)/P[i+K]
    ans-=m
    ans+=a
    A.append(ans)
ans=A[0]
for i in range(1,N-K+1):
    if A[i]>ans:
        ans=A[i]
#print(A)
print(ans)

Submission status: Accepted

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

exv = 0

for j in range(k):
    exv += (ls[j] + 1) / 2

ans = exv

for i in range(k, n):
    exv += (ls[i] + 1) / 2
    exv -= (ls[i - k] + 1) / 2
    
    if exv > ans:
        ans = exv

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    maxI = 0
    maxV = sum(P[:K])
    curV = maxV
    for i in range(1, N-K+1):
        curV = curV + P[i+K-1] - P[i-1]
        if curV > maxV:
            maxV = curV
            maxI = i

    res = (sum(P[maxI:maxI+K]) + K) / 2.0
    print(res)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = s_tmp = sum(p[0:K])
for i in range(N-K):
    s_tmp = s_tmp - p[i] + p[i+K]
    if s < s_tmp:
        s = s_tmp

print((s+K)/2)

Submission status: Accepted

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

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

ans = sum(p[:K])
now = sum(p[:K])

for i in range(K, N):
    now = now + p[i] - p[i-K]
    if now > ans:
        ans = now

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate


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

# 累積和
B = [0] + A
B = list(accumulate(B))

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

print((max(ans)+K)/2)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
dd = [0] * (n + 1)
for i in range(1, n + 1):
    dd[i] = dd[i - 1] + p[i - 1]
total = 0
index = 0
j = 0
while j < n + 1:
    if j + k >= n + 1:
        break
    now = dd[j + k] - dd[j]
    if now > total:
        total = now
        index = j
    j += 1
ans = 0
for i in range(k):
    aa = index + i
    ans += p[index + i] + 1
ans /= 2
print(ans)

Submission status: Accepted

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

s = 0
for i in range(K):
    s += 1 + Ps[i]

ans = s

for i in range(K, N):
    s = s - Ps[i-K] + Ps[i]
    ans = ans if ans > s else s

print(ans / 2)

Submission status: Accepted

Solution code:
nums = list(map(lambda x: int(x), input().split(" ")))
n = nums[0]
k = nums[1]
ps = list(map(lambda x: (int(x) + 1) / 2, input().split(" ")))
res = 0.0
su = 0.0
sums = [0] * n
for i, s in enumerate(ps):
    su = su + s
    sums[i] = su
for i in range(n - k + 1):
    if i == 0:
        res = sums[k - 1]
    else:
        res = max(res, sums[i + k - 1] - sums[i - 1] )
print(res)

Submission status: Accepted

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

tem=0
ans=0

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

for i in range(1,n-k+1):
    fi=p[i-1]/2 +1/2
    la=p[i+k-1]/2 +1/2
    tem=tem-fi+la
    ans=max(ans,tem)

print(ans)

Submission status: Accepted

Solution code:
#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))


n_given,k_given =input_multiple_number()
pi_given = input_multiple_number_as_list()

#initial
wk = sum(pi_given[0:k_given])
maxi = wk

for i in range(n_given - k_given):
    wk = wk - pi_given[i] + pi_given[i+k_given]
    maxi = max(maxi,wk)

print((maxi + k_given )/2)

Submission status: Accepted

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

dp=[0]*n
ans,total=0,0
for i in range(n):
  dp[i]=((1/2)*P[i]*(P[i]+1)) / P[i]
  if i>=k:
    ans=max(ans,total)
    total-=dp[i-k]
  total+=dp[i]
ans=max(ans,total)
print(ans)

Submission status: Accepted

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

tmp_sum = max_sum
for i in range(K,N):
    tmp_sum -= P[i-K]
    tmp_sum += P[i]
    if tmp_sum > max_sum:
        max_sum = tmp_sum


ret = max_sum/2 + K/2
print(ret)

Submission status: Accepted

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

s = [0]

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

for i in range(n):
  s.append(kitai(p[i]) + s[-1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = [int(e) for e in input().split()]
p = [int(e) for e in input().split()]
sum = 0
max_index = 0
for i in range(0,k):
    sum += p[i]
max_sum = sum
for i in range(1,n-k+1):
    sum = sum - p[i-1] + p[i+k-1]
    if sum > max_sum:
        max_sum = sum
        max_index = i

res = 0
for i in range(0,k):
    res += (p[max_index + i] + 1)/2

print(res)

Submission status: Accepted

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

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    if i == 0:
        ave_pl.append(p_sum/p)
    else:
        ave_pl.append(ave_pl[i-1]+(p_sum/p))

ans = 0
if n == k:
    print(ave_pl[-1])
else:
    for i in range(k-1, n):
        if i == 0:
            ans = max(ans, ave_pl[i])
        else:
            ans = max(ans, ave_pl[i]-ave_pl[i-k])
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
L = [0]
P = list(map(int,input().split()))
L = L+P
cur = 0
for i in range(n+1):
  if i != 0:
    L[i] = (L[i]+1)/2
    L[i] += L[i-1]
for i in range(n-k+1):
  cur = max(L[i+k]-L[i],cur)
print(cur)

Submission status: Accepted

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

p1 = (sum(p[:k]) + k)/2

ansum = [p1]
for i  in range(len(p)-k):
    p1 = p1 - (p[i]+1)/2 + (p[i+k]+1)/2
    ansum.append(p1)

print(max(ansum))

Submission status: Accepted

Solution code:
import itertools
n, k = map(int, input().split())
p = list(map(int, input().split()))
ki = [0]*1001
for i in range(1, 1001):
    ki[i] = ki[i-1]+i

pp = []
for pa in p:
    pp.append(ki[pa]/pa)

# print(pp)
ppp = [0] + list(itertools.accumulate(pp))
# print(ppp)
ans = 0
for i in range(n-k+1):
    # print(ppp[i+k]-ppp[i])
    ans = max(ans, ppp[i+k]-ppp[i])

print("{0:.12f}".format(ans))

Submission status: Accepted

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

n, k = map(int, input().split())
p = list(map(int, input().split()))
s = [0 for i in range(k)]
ans = 0
mm = 0
j = 0

for i in range(n):
  if j < k:
    s[j] = sumA(p[i])/p[i]
    mm+=s[j]
  else:
    mm-=s[j%k]
    mm+= sumA(p[i])/p[i]
    if ans < mm:
      ans = mm
    s[j%k] = sumA(p[i])/p[i]
  j+=1
  
print(max(mm, ans))

Submission status: Accepted

Solution code:
from collections import deque
n, k = (int(x) for x in input().split())
p = [int(x) for x in input().split()]
d = deque(p)
tmax = 0
pmax = 0
for i, pp in enumerate(p):
    pmax += pp
    if i >= k:
        pmax -= d.popleft()
    if pmax > tmax:
        tmax = pmax
ans = (tmax + k) / 2
print(ans)

Submission status: Accepted

Solution code:
# ABC154 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
ans=0
p=nl()
# p=set(p)
# p=list(p)
# p.sort(reverse=True)
e=[0]*n

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

s=sum(e[:k])

t=0
ans=0
for i in range(n-k+1):
    if i==0:
        t=s
        ans=max(ans,t)
        continue
    t+=e[i+k-1]
    t-=e[i-1]
    ans=max(ans,t)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    s, t = input().split()
    a, b = LI()
    u = input()
    if u == s:
        print("{} {}".format(a - 1, b))
    elif u == t:
        print("{} {}".format(a, b - 1))
    return


# B
def B():
    s = input()
    print('x' * len(s))
    return


# C
def C():
    n = I()
    a = LI()
    s = set()
    for i in a:
        s.add(i)
    if len(s) == n:
        print('YES')
    else:
        print('NO')
    return


# D
def D():
    N, K = LI()
    p = LI()
    map_p = list(map(lambda x: (1 + x), p))
    cumsum_p = [0] * N
    ans_p = [0] * N
    cumsum_p[0] = map_p[0]
    ans_p[0] = map_p[0]
    for i in range(1, N):
        cumsum_p[i] = cumsum_p[i - 1] + map_p[i]
        ans_p[i] = ans_p[i - 1] + map_p[i]
    for i in range(K, N):
        ans_p[i] -= cumsum_p[i - K]
    print(max(ans_p[K - 1:]) / 2.0)
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P = list(map(int, input().split()))
A = []
#A.append(P[0])
for i in range(N):
    k=((1+P[i])*(P[i]))/(2*P[i])
    A.append(k)
c=0
for i in range(K):
    c+=A[i]
ans=c
#print(A)
for i in range(K,N):
    c=c-A[i-K]+A[i]
    if(ans<c):
        ans=c
print(ans)

Submission status: Accepted

Solution code:
k,n=map(int,input().split())
ls=list(map(int,input().split()))
sum_ls=ls[:n]
rest_ls=ls[n:]
tmp=sum(sum_ls)
mx=tmp
for i in range(k-n):
    first=ls[i]
    last=ls[i+n]
    tmp=tmp-first+last
    if mx<tmp:
        mx=tmp


print((mx+n)/2)

Submission status: Accepted

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

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

saidai = 0
for i in range(n-k+1):
    if sekiwa[i+k] - sekiwa[i] >= saidai:
        saidai = sekiwa[i+k] - sekiwa[i]
        hajimari = i

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

print(ans)

Submission status: Accepted

Solution code:
a=input()
b=input()
d=a.split()
N=int(d[0])
K=int(d[1])
c=b.split()
s=0
max=0
for f in range(K):
    s=s+int(c[f])
max=s
for i in range(N-K):
    if(K+i<N):
      s=s+int(c[K+i])-int(c[i])
      if(s>max):
          max=s
    else: break
print(float((max+K)/2))

Submission status: Accepted

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

def expectation(p):
    return (p - 1) / 2 + 1

h = {}

answer = 0
for i in range(N):
    if i < K - 1:
        answer += expectation(P[i])
    elif i == K - 1:
        answer += expectation(P[i])
        h[i] = answer
    else:
        answer += expectation(P[i])
        answer -= expectation(P[i - K])
        h[i] = answer
print(max(list(h.values())))

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
sum = [0]*(len(a)+1)
for i,val in enumerate(a):
    ex = val*(val+1)/2/val
    sum[i+1] = sum[i]+ex
ma = 1
for i in range(n):
    if i+k <= n:
        ma = max(ma,sum[i+k]-sum[i])
    else:
        break
print(ma)

Submission status: Accepted

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

# (n*(n+1))/2 /n == (n+1)/2

P2 = [(n+1) for n in P]

S = sum(P2[:K])
max_s = S
for i in range(1, N-K+1):
    S -= P2[i-1]
    S += P2[i+K-1]

    max_s = max(max_s, S)

# print(f'{max_s:.9f}')
print('{:.10f}'.format(max_s/2))

Submission status: Accepted

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

Submission status: Accepted

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

s = sum(P[0:K])
m = s
id = 0
for i in range(1, N - K + 1):
    s += (P[i + K - 1] - P[i - 1])
    if s > m:
        id = i
        m = s

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

Submission status: Accepted

Solution code:
from itertools import accumulate


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

d = {}
for i in range(1, 1001):
    d[i] = (i + 1) * (i / 2) / i

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

cum = list(accumulate(E))
mx = 0
idx = 0
ans = 0
for i in range(N-K+1):
    if i == 0:
        mx = max(mx, cum[i+K-1])
    else:
        mx = max(mx, cum[i+K-1] - cum[i-1])

print(mx)

Submission status: Accepted

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

tmp=0
for i in p[:k]:
    tmp+=(1+i)/2
li=[tmp]

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

    tmp=li[i]
    tmp-=(1+p[i])/2
    tmp+=(1+p[k+i])/2
    
    li.append(tmp)


print(max(li))

Submission status: Accepted

Solution code:
from itertools import accumulate
def solve():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    A = [a * (a + 1) / 2 / a for a in P]
    B = [0.0] + list(accumulate(A))
    ans = 0
    for i in range(k, n + 1):
        ans = max(ans, B[i] - B[i - k])
    print(ans)
solve()

Submission status: Accepted

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

DP=[0]*1001
for i in P:
    if DP[i]==0:
        DP[i]=(i*(i+1)//2)/i
    K.append(DP[i])

K.append(0)
ans=sum(K[:k])
score=sum(K[:k])
for i in range(n-k+1):
    score -=K[i]
    score +=K[i+k]
    ans=max(ans,score)
print(ans)

Submission status: Accepted

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

    kti = [0] * n
    sm = [0] * (n)
    for i,pp in enumerate(p):
        kti[i] = (pp + 1) / 2
        if i == 0:
            sm[0] = kti[0]
        else:
            sm[i] = sm[i-1] + kti[i]

    ans = sm[k-1]
    j = 0
    for i in range(k,len(sm)):

        tmp = sm[i]-sm[j]
        ans = max(ans,tmp)
        j += 1
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

from collections import deque
d=deque(p_list[:k])
max_val = sum(p_list[:k])
total = max_val
max_idx = 0

for i in range(k, n):
    num = p_list[i]
    total = total + num - d.popleft()
    if total > max_val:
        max_val = total
        max_idx = i-k+1
    d.append(num)

def exp(n):
    return 1+(n-1)*0.5

print(sum(map(exp, p_list[max_idx:max_idx+k])))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int, input().split()))
for i in range(n):
	p[i]=(1+p[i])/2
cs=[]
sum=0
for i in range(n):
	sum+=p[i]
	cs.append(sum)
ans=cs[k-1]
for i in range(1,n-k+1):
	ans=max(ans,cs[i+k-1]-cs[i-1])
print('{:.8f}'.format(ans))

Submission status: Accepted

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

    def experience(x):
        return (x + 1) / 2  # 1からxまで出るサイコロの出目の期待値

    ans = []
    tmp = 0
    for i in range(K):
        tmp += experience(P[i])
    ans.append(tmp)
    for i in range(K, N):
        tmp -= experience(P[i - K])
        tmp += experience(P[i])
        ans.append(tmp)
    return max(ans)

print(d_dice_in_line())

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=[int(i)+1 for i in input().split()]
left = 0
right = K
max_=sum(P[:K])
ans=max_
#print(max_)
for _ in range(N-K):
    ans=max(ans,max_ - P[left] + P[right])
    max_=max_ - P[left] + P[right]
    left += 1
    right += 1
print(ans/2)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)

@lru_cache(maxsize=None)
def calc(n):
    if n == 1:
        return 1
    else:
        return n + calc(n - 1)

def main():
    N, K = map(int, input().split())
    P = tuple(map(int, input().split()))

    l = 0
    sum_v = 0
    max_v = 0
    max_i = 0
    ind = 0
    for i in range(N-K+1):
        while l < K:
            sum_v += P[ind]
            ind += 1
            l += 1
        if sum_v > max_v:
            max_v = sum_v
            max_i = i
        l -= 1
        sum_v -= P[i]
    print(sum([calc(p) / p for p in P[max_i:max_i+K]]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_sum = sum(p_list[:K])
now_sum = max_sum
for i in range(K, N):
    now_num = p_list[i]
    now_sum -= p_list[i - K]
    now_sum += now_num
    if now_sum > max_sum:
        max_sum = now_sum

print((max_sum + K) / 2)

Submission status: Accepted

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

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

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

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

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

mm=0
inx=-1
for i in range(len(b)-k):
 if b[i+k]-b[i]>=mm:
  inx=i
  mm=b[i+k]-b[i]


ans=0
for j in range(inx,inx+k):
  ans+=((p[j]*(p[j]+1))*0.5)*(1/p[j])

print(ans)

Submission status: Accepted

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

sum=[0]*N
sum_f=0

for j in range(K):
  sum_f += (p[j]+1)/2
sum[0]=sum_f
  
for i in range(1,N-K+1):
  sum[i]=sum[i-1] - (p[i-1]+1)/2 + (p[i+K-1]+1)/2
  
print(max(sum))

Submission status: Accepted

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

maxx = 0
def total(x):
    return int(x*(x+1)/2)

kitai_P = [total(x)/x for x in P]

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p_list = list(map(int,input().split()))
ans_list = []
def E(me):
    if me == 1:
        return 1
    else:
        return ((1+me)*me/2)/me
E_list_ruisekiwa = [0,]
for i in range(N):
    E_list_ruisekiwa.append(E_list_ruisekiwa[i]+E(p_list[i]))

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

Submission status: Accepted

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

List2=[0]*(N-K+1)
for i in range(K):
    List2[0] += P_List[i] 

ans = List2[0]

for i in range(1,N-K+1):
    List2[i]=List2[i-1]+P_List[i+K-1]-P_List[i-1]
    if ans < List2[i]:
        ans = List2[i]

print(ans)

Submission status: Accepted

Solution code:
import numpy

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

List=list(map(int,input().split()))
EList = []

for i in range(len(List)):
  a = List[i]
  b = (a+1)/2
  EList.append(b)
  

res = numpy.cumsum(EList)
res = numpy.insert(res,0,0)
ans = 0
for i in range(len(List)+1):
  if i < K-1:
    ans = 0
  else:
    ans = float(max(res[i] - res[i-K],ans))

print(float(ans))

Submission status: Accepted

Solution code:
# import numpy as np
# S,T = input().split()
N,K = list(map(int,input().split()))
# N = int(input())
ps = list(map(int,input().split()))
Es = []
for p in ps:
    Es.append((1+p)/2)
beg = 0
end = K
ans = sum(Es[beg:end])
prev = ans

while end < N:
    prev = prev - Es[beg] + Es[end]

    if prev > ans:
        ans = prev
    beg += 1
    end += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
#n = int(input())
#s, t = map(str, input().split())
n, k = map(int, input().split())
#s = input()
p = list(map(int, input().split()))

x = sum(p[:k])
y = 0
max = 0
for i in range(n-k):
  y = y + p[k+i] - p[i]
  if y > max:
    max = y

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

Submission status: Accepted

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

summax = sum(p[0:K])
sumnow = sum(p[0:K])
maxi = 0

for i in range(1, N-K+1):
  sumnow = sumnow - p[i-1] + p[K+i-1]
  if sumnow > summax:
    summax = sumnow
    maxi = i

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
l = []
for x in p:
    tmp = 1.0+0.5*(float(x)-1.0)
    l.append(tmp)
max = sum(l[:k])
now = max
for i in range(k,n):
    now = now + l[i] - l[i-k]
    if now >= max:
        max = now
print(max)

Submission status: Accepted

Solution code:
import numpy as np

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

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


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_ls = list(map(int, input().split()))
ave_ls = []
'''
if n == 1:
    ave_ls.append(p_ls[0]*0.5+1)
elif n == 2:
    ave_ls.append((p_ls[0]+p_ls[1])*0.5+1)
else:
    for i in range(n-2):
        ave_ls.append((p_ls[i]+p_ls[i+1]+p_ls[i+2])*0.5+1)
'''
now_ave = 0
for i in range(k):
    now_ave +=p_ls[i]
ave_ls.append(now_ave*0.5+0.5*k)
for i in range(n-k):
    #print(now_ave)
    now_ave -=p_ls[i]
    now_ave+=p_ls[i+k]
    #print("p_ls[i]",p_ls[i],"p_ls[i+k-1]",p_ls[i+k-1])
    ave_ls.append(now_ave*0.5+0.5*k)
print(max(ave_ls))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    p = [int(_) for _ in raw_input().split()]
    sumNk = 0
    for i in range (K):
        sumNk += p[i]
    maxSumNk = sumNk
    for i in range (K, N):
        sumNk = sumNk - p[i - K] + p[i]
        if sumNk > maxSumNk:
            maxSumNk = sumNk
    ret = (maxSumNk + K) * 0.5
    print ret

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:

n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[0]*(n-k+2)

for j in range(0,k):
    count+=(p[j]/2+0.5)
ans[0]=count
z=1
#print(ans)
for i in range(k,n):
    #print(p[i],p[z-1])
    ans[z]=ans[z-1]-(p[z-1]/2+0.5)+(p[i]/2+0.5)
    z+=1
#print(ans)
print(max(ans))
"""
n,k=map(int,input().split())
p=list(map(int,input().split()))
count=0
ans=[]
for i in range(n-k+1):
    for j in range(i,k+i):
        count+=(p[j]/2+0.5)

    ans.append(count)
    count=0
print(ans)
print(max(ans))
"""

Submission status: Accepted

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

sum_k = [0] * N
tmp = 0
for i in range(K):
    tmp += p[i]
sum_k[0] = tmp
max_sum = tmp
candidate = 0
for i in range(len(p)-K):
    sum_k[i+1] = sum_k[i] - p[i] + p[i+K]
    if max_sum < sum_k[i+1]:
        max_sum = sum_k[i+1]
        candidate = i+1


dice = [-1] * 10000

ans = 0
for i in range(candidate, candidate + K):
    tmp = 0
    if dice[p[i]+1] != -1:
        ans += dice[p[i]+1]
        continue
    for j in range(1, p[i]+1):
        tmp += j * (1 / p[i])
    dice[p[i]+1] = tmp
    ans += tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(max_exp)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def get_range_sum(l,s,e):
    return l[e] - l[s]

def main():
    N,K = map(int, input().split())
    pp = list(map(int, input().split()))
    pp_rui = defaultdict(int)
    for i in range(N):
        pp_rui[i+1] = pp_rui[i] + pp[i]
    #print(pp_rui)
    emax = 0
    cc = K/2
    for i in range(N-K+1):
        res = get_range_sum(pp_rui, i, i+K) + K
        res = res / 2
        #print(i, res)
        emax = max(emax, res)
    print("{:.12f}".format(emax))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

def prime(n:int):
    cnt = 2
    ans = set()
    while n > 1:
        if n%cnt == 0:
            ans.add(cnt)
        while n%cnt == 0:
            n //= cnt
        cnt += 1
    return ans

def main():
    N,K = map(int,input().split())
    P = [(int(p)+1)/2 for p in input().split()]

    S = [P[0]]
    for p in P[1:]:
        S.append(S[-1] + p)
    S += [0]
    ans = 0
    for i in range(N - K + 1):
        ans = max(ans,S[i + K - 1] - S[i-1])
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 2020/02/09
# AtCoder Beginner Contest 154 - D

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

acm = [0] * n

# Calc
for i in range(n):
    if i-k < 0:
        minu = 0
    else:
        minu = p[i-k]
    acm[i] = acm[i-1] + p[i] - minu

ans = (max(acm) + k) / 2

# Output
print(ans)

Submission status: Accepted

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

ki = [0] * N

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

ans = 0

for j in range(K):
    ans += ki[j]

b_result = ans

for times in range(N-K):
    tmp = b_result
    tmp = tmp - ki[times] + ki[K+times]
    if tmp >= ans:
        ans = tmp
    b_result = tmp

print(ans)

Submission status: Accepted

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

N,K=input_int()
P= many_int()

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



maxs = 0
temp = sum(kitaiti[:K])
for i in range(N-K+1):

    temp += kitaiti[i+K]
    temp -= kitaiti[i]

    if temp > maxs:
        maxs = temp


print(maxs)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
p=[int(x) for x in input().split()]
s=0
for c in range(k):
    s+=p[c]
t=s
for c in range(n-k):
    t+=p[c+k]-p[c]
    if t>s:
        s=t
print((s+k)/2)