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())
l=list(map(int,input().split()))

d={}

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

#print(d)

dp=[]
dp.append(d[l[0]])
for i in range(1,n):
  dp.append(dp[i-1]+d[l[i]])

#print("this is dp",dp)

mx=dp[k-1]
for i in range(n-k):
  we=dp[i+k]-dp[i]
  #print(we,dp)
  if we>=mx:
    mx=we
print(mx)

Submission status: Accepted

Solution code:
N, K = [int(n) for n in input().split()]
#dice = [int(n) for n in input().split()]
evs = [(1 + int(n))/2 for n in input().split()]
cumsum = [0]

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

k_cum = [cumsum[i+K] - cumsum[i] for i in range(N-K+1)]

print(max(k_cum))

Submission status: Accepted

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

Submission status: Accepted

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

X = []

for i in p:
  X.append((i + 1) / 2)

fK = 0
for i in range(K):
  fK += X[i]

X_sum = [fK]

for i in range(N - K):
  X_sum.append(X_sum[i] - X[i] + X[i+K])

print(max(X_sum))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

exps = []
_sum = 0
for v in P:
    _sum += (1+v)/2
    exps.append(_sum)

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

print(ans)

Submission status: Accepted

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

Dices = list(map(lambda n:(n+1)/2,Dices))
import numpy as np 
Dices = np.cumsum(Dices)
# from collections import deque

# d=deque([])
# total= 0
# for i in range(N):
#     d.append((Dices[i]+1)/2)
#     if len(d)==K:
#         total = max(total,sum(d))
#         d.popleft()

# print(total)

#累積和
S=np.append(0,Dices)
total = 0
# for i in range(N+1):
#     S[i] = sum(Dices[:i])

for j in range(N-K+1):
    total = max(total,S[j+K]-S[j])

print(total)

Submission status: Accepted

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

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

print(max(l))

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
list = list(map(int, input().split()))

list_sum=[0]
for i in range(n):
    list_sum.append(list_sum[i]+list[i])
max_sum = 0
for i in range(n-k+1):
    sum_num = list_sum[i+k]-list_sum[i]
    if sum_num>max_sum:
        max_sum = sum_num
print((max_sum+k)/2)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def tsum(l, r):
    return (r + l) * (r - l + 1) // 2

def exp(num):
    return tsum(1, num) / num

def solve():
    n, k = MI()
    P = LI()

    E = [0] * n
    pre = 0
    for i in range(n):
        E[i] = pre + exp(P[i])
        pre = E[i]
    # print(E)

    p = E[0]
    mx = E[k-1]
    for j in range(k, n):
        diff = E[j] - E[j-k]
        # print(diff)
        if mx < diff:
            mx = diff
    print(mx)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
m = [(maximum + 1) / 2 for maximum in p]
S=[0]*(N+1)
for i in range(N):
  S[i+1]=S[i]+m[i]
ans=0

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

Submission status: Accepted

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

exp = [(1+i)/2 for i in p]

s = []
sums = 0
for i in exp:
    sums += i
    s.append(sums)

exps = [s[k-1]]
for i in range(k,len(p)):
    exps.append(s[i] - s[i-k])
print(max(exps))

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
p_ls = list(map(int, input().split()))
e_ls = [0] * n
for i in range(n):
    p = p_ls[i]
    e = (p*(1+p) // 2) / p
    e_ls[i] = e
e_csum = list(np.cumsum(e_ls))
max_exp = 0
for start in range(n):
    if start > 0 and start+k-1 < n:
        sum_exp = e_csum[start+k-1] - e_csum[start-1]
    elif start == 0:
        sum_exp = e_csum[start + k - 1]
    max_exp = max(max_exp, sum_exp)
print(max_exp)

Submission status: Accepted

Solution code:
N,K=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
e=[(i+1)*0.5 for i in p]
ex=[]

for i in range(N):
  if i==0:
    ex.append(e[0])
  else:
    ex.append(ex[i-1]+e[i])

ans=0
ex.insert(0,0)
for i in range(N-K+1):
  if ans<ex[i+K]-ex[i]:
    ans=ex[i+K]-ex[i]
print(ans)

Submission status: Accepted

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

c_s_list = [0] #Cumulative sum_list
c_sum = 0 #Cumulative sum
for dice in p_list:
    average = (dice + 1) / 2 #ダイスの期待値
    c_sum += average
    c_s_list.append(c_sum)

ans = 0
for i in range(N-K+1):
    tmp = c_s_list[i+K] - c_s_list[i]
    if tmp >= ans:
        ans = tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = []
for p in P:
    Q.append(sum(range(1, p + 1)) / p)
max = 0
max_i = 0
tmp = 0
for i in range(N - K + 1):
    if i == 0:
        for j in range(K):
            tmp += Q[j]
    else:
        tmp = tmp + Q[i + K - 1] - Q[i - 1]
    if max < tmp:
        max = tmp
        max_i = i
print(max)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[]
b=[0]*n
q=0
for i in range(n):
  a.append((1/2)*(p[i]+1))
for j in range(k):
  q+=a[j]

b[0]=q

for l in range(1,n-k+1):
  b[l]=b[l-1]-a[l-1]+a[k+l-1]
print(max(b))

Submission status: Accepted

Solution code:
import itertools
n, k=map(int, input().split())
a=list(map(int, input().split()))
a.insert(0, 0)

ary=[0]
for i in range(1,n+1):
    ary.append((a[i]+1)/2)

cumsum=itertools.accumulate(ary)
ary2=list(cumsum)
ans=0

for i in range(n-k+1):
    tmp=ary2[i+k]-ary2[i]

    if tmp > ans:
        ans=tmp

print(ans)

Submission status: Accepted

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

from collections import deque
d = deque()

maxE = 0
sumE = 0

# pの期待値(p+1)/2
for i in range(n):
    p = arr[i]
    e = (p+1)/2
    # print(e)
    sumE += e
    d.append(e)
    # print(sumE)
    if i+1 >= k:
        if sumE > maxE:
            maxE = sumE
        sumE -= d.popleft()

print(maxE)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
ex = [1/2*(i+1) for i in p]
total = [0]

for i in range(N):
    total.append (total[i] + ex[i])

ans = 0
for i in range(N+1-K):
    tmp = total[i+K] - total[i]
    if ans < tmp:
        ans = tmp

print (ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
ex=[1/2*(i+1) for i in p]
ruiseki=[0]
ans=0

for i in range(N):
  ruiseki.append(ruiseki[i]+ex[i])


for i in range(N+1-K):
  if ans<ruiseki[i+K]-ruiseki[i]:
    ans=ruiseki[i+K]-ruiseki[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

b[0] = sum(e[0:k])
for i in range(1, len(b)):
  b[i] = e[i+k-1] + b[i-1] - e[i-1]
print(max(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy as c

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


def solve(N, p, K):
    ans = sum(p[:K])
    #print(N, K, P)
    #ans = 0
    ans = c.copy(sum(p[:K]))
    sm = c.copy(ans)
    for i in range(K, N):
        #print(i-K, p[i-K], i, p[i])
        sm = sm - p[i-K] + p[i]
        ans = max(ans, sm)
        # print(ans)
    return ans


print(1/2.0 * k + 1.0/2 * solve(n, P, k))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    p = [(p_ +1)/2 for p_ in p]
    temp = sum(p[0:K])
    max_s = temp

    for i in range(K, N):
        temp = temp - p[i-K] + p[i]
        max_s = max(max_s, temp)
    
    print(max_s)




    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    def f(pp):
        return pp * (pp + 1) / 2 / pp
    q = tuple(map(f, p))
    ma = su = sum(q[:K])
    for i, (qq, qqq) in enumerate(zip(q, q[K:]), 1):
        su = su - qq + qqq
        ma = max(ma, su)
    return ma


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, p))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
max_value = 0
ans_p = 0

s = [0]*(n+1)
for i, _p in enumerate(p):
    s[i+1] = s[i] + _p

for i in range(n-k+1):
    sum_ = s[i+k] - s[i]
    if (max_value < sum_):
        max_value = sum_

print((max_value+k)/2)

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

p_sm=0

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

p_mx=p_sm

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

print((p_mx+k)/2)

Submission status: Accepted

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

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

tmp = sum(p[:k])
res = tmp
start = 0
end = k-1
for i in range(n-k):
  tmp -= p[i]
  tmp += p[k+i]
  if res < tmp:
    res = tmp
    start = i+1
    end = k+i

ans = 0
for i in range(start,end+1):
  if p[i] % 2 == 0:
    ans += ((p[i]+1) * (p[i] // 2)) / p[i]
  else:
    ans += (1 + p[i]//2 + (p[i]+1) * (p[i] // 2)) / p[i]
print(ans)

Submission status: Accepted

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

res = 0
flag = 0
ans = 0
Sum = 0

for i in range(n-k+1):
    if i == 0:
        Sum = sum(p[i:i+k])
        res = Sum
        continue
    
    Sum -= p[i-1]
    Sum += p[i+k-1]
    
    if res < Sum:
        res = Sum
        flag = i
        
for i in range(k):
    if p[flag+i]%2 == 0:
        ans += (p[flag+i]/2) + 0.5
    else:
        ans += (p[flag+i] + 1)/2
        
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P = list(map(int, input().split()))
P_sum = 0
for i in range(K):
    P_sum += P[i]
P_max = P_sum
for i in range(N-K):
    P_sum = P_sum + P[K+i]-P[i]
    if P_sum > P_max:
        P_max = P_sum
print(P_max/2+0.5*K)

Submission status: Accepted

Solution code:
def myAnswer(N:int,K:int,P:list) ->  int:
   ans =[]
   for p in P:
      tmp =(p+1)/2
      ans.append(tmp)
   # print(ans)
   accum = [sum(ans[:K])]
   for i in range(K,N,1):
      accum.append(accum[-1]-ans[i - K]+ans[i])
   # print(accum)
   return max(accum)

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   P = list(map(int,input().split()))
   print(myAnswer(N,K,P[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int,input().split())
p = np.array(input().split(),dtype=int)

sum = 0
for i in range(k):
    sum += p[i]
max = sum
for i in range(n-k):
    sum = sum+p[k+i]-p[i]
    if max<sum:
        max = sum
print(max/2+0.5*k)

Submission status: Accepted

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

    for i in range(n):
        p[i]=(p[i]+1)/2
    s = [0]
    for i in range(n):
        s.append(s[i]+p[i])
    m = 0
    for i in range(n-k+1):
        if m<s[i+k]-s[i]:
            m = s[i+k]-s[i]
    print(m)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

MAX = 0
for i in range(N-K+1):
    if i == 0:
        SUM = 0
        for j in range(K):
            SUM += (A[i+j]+1)/2

    else:
        SUM += (A[i+K-1]+1)/2
        SUM -= (A[i-1]+1)/2
    
    if MAX < SUM:
        MAX = SUM

print(MAX)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ans = 0
save = 0
sum = 0
ans_o = 0
ans_check = 0
for j in range(k):
    ans_check += p_list[0 + j]
    ans_o += p_list[0 + j]
for i in range(1,n-k+1):
    ans = ans_o-p_list[i-1]+p_list[i+k-1]
#    print(ans)
    if ans > ans_check:
        save = i
        ans_check = ans
    ans_o = ans
    #print(save)

for i in range(save,save+k):
    sum += p_list[i]*0.5 + 0.5
print(sum)

Submission status: Accepted

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

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

num = sum(num_li[:k])
ans = num
for j in range(n-k):
    num = num-num_li[j]+num_li[j+k]
    ans = max(num, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    p[i] = (p[i] + 1)/2
ans = 0
tmp = 0
for i in range(k):
    tmp += p[i]
    ans += p[i]
for i in range(1,n - k + 1):
    tmp = tmp - p[i - 1] + p[i + k - 1]
    if ans < tmp:
        ans = tmp
print("{:.12f}".format(ans))

Submission status: Accepted

Solution code:
from itertools import*
i = lambda f: map(f, input().split())
n, k = i(int)
p = [0] + list(accumulate(i(lambda x: -~int(x)/2)))
print(max(p[i+k]-p[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()))
l = [0]

for i in range(1,1001):
    t = 0
    for j in range(i+1):
        t+=j
    l.append(t/i)

ans = 0

for e,i in enumerate(p):
    p[e] = l[i]
P = [0]*(n+1)
P[0] = 0
for e,i in enumerate(p):
    P[e+1] +=P[e]+i
M = 0  
for i , j in zip(P,P[k:]):
    M = max(M,j-i)
print(M)

Submission status: Accepted

Solution code:
from itertools import accumulate
n, k = map(int, input().split())
l = list(map(int, input().split()))
l = list(map(lambda x: (((x + 1) * x) / 2) / x, l))
s = list(accumulate(l))
l_2 = [s[k - 1]]
for i in range(len(l) - (k - 1) - 1):
    l_2 += [s[i + k] - s[i]]
print(max(l_2))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P = list(map(int,input().split()))
Px  =[]
for i in range(N):
    Px.append((1+P[i])/2)
temp_num = sum(Px[0:K])
temp_max = sum(Px[0:K])
#print(Px)
for j in range(N-K):
    #print(temp_num)
    temp_num = temp_num-Px[j]+Px[j+K]
    if temp_max <temp_num:
        temp_max=temp_num
print(temp_max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=list(map(lambda x:(int(x)+1)/2,input().split()))
i=0
summ=0
maxx=0
for j in range(b):
  summ+=c[i]
  i+=1
maxx=summ
for j in range(a-b):
  summ+=c[i]
  summ-=c[i-b]
  i+=1
  if maxx<summ:maxx=summ
print(maxx)

Submission status: Accepted

Solution code:

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

temp_num = sum(line[0:K])
temp_max = temp_num

for i in range(N - K):
    temp_num = temp_num - line[i] + line[i + K]
    if temp_num > temp_max:
        temp_max = temp_num


print((temp_max + K) / 2)

Submission status: Accepted

Solution code:
num,renzoku=map(int,input().split())
dices=list(map(int,input().split()))

sum_si=sum(dices[0:renzoku])
max_si=sum_si
for i in range(1,num-renzoku+1):
  sum_si=sum_si-dices[i-1]+dices[i+renzoku-1]
  if max_si<sum_si:
    max_si=sum_si
print((renzoku+max_si)/2)

Submission status: Accepted

Solution code:
num,renzoku=map(int,input().split())
dices=list(map(int,input().split()))
expects=[0]*num
Si=[0]*(num+1)
for i in range(1,num+1):
  Si[i]=Si[i-1]+(1+dices[i-1])/2
max_Si=0
for i in range(0,num-renzoku+1):
  if max_Si<Si[i+renzoku]-Si[i]:
    max_Si=Si[i+renzoku]-Si[i]
print(max_Si)

Submission status: Accepted

Solution code:
num,renzoku=map(int,input().split())
dices=list(map(int,input().split()))
expects=[0]*num
for i in range(num):
  pi=dices[i]
  expects[i]=(1+pi)/2
Si=[0]*(num+1)
for i in range(1,num+1):
  Si[i]=Si[i-1]+expects[i-1]
max_Si=0
for i in range(0,num-renzoku+1):
  if max_Si<Si[i+renzoku]-Si[i]:
    max_Si=Si[i+renzoku]-Si[i]
print(max_Si)

Submission status: Accepted

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

import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    Et = [0]*(N+1)
    for i in range(N):
        Et[i+1] = Et[i] + (1+P[i])/2
    ret = 0
    for i in range(N-K+1):
        ret = max(ret, Et[i+K]-Et[i])
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, y = map(int,input().split())
p = list(map(int,input().split()))
ans = 0

for i in range(x-y+1):
    if i == 0:
        z = sum(p[:y])
    else:
        z = z - n + p[i+y-1]
    n = p[i]
    if z > ans:
        ans = z

print((ans+y)/2)

Submission status: Accepted

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

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

tmp = sum(P[:K])
maxV = tmp

for i in range(N-K):
  tmp += P[i+K] - P[i]
  maxV = max(maxV, tmp)
print(maxV)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

tmp = sum([expect(p) for p in P[:K]])
maxV = tmp
for i in range(N-K):
  tmp -= expect(P[i]) 
  tmp += expect(P[i+K])
  maxV = max(maxV, tmp)
print(maxV)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n,k=map(int,input().split())
    P=np.array([int(_) for _ in input().split()])
    PP=(P+1)/2
    PP_cum=np.cumsum(PP)
    PP_cum=np.insert(PP_cum,0,0)
    print(np.max(PP_cum[k:]-PP_cum[:n-k+1]))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n,k=map(int,input().split())
    P_num=np.array([int(_) for _ in input().split()])
    PP=(P_num+1)/2
    PP_cum=np.cumsum(PP)
    PP_cum=np.insert(PP_cum,0,0)
    ans=PP_cum[k:]-PP_cum[:n-k+1]
    print(np.max(ans))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
import numpy as np
def main():
    n,k=map(int,input().split())
    P=[int(_) for _ in input().split()]
    P_num=np.array(P)
    PP=(P_num+1)/2
    PP_cum=np.cumsum(PP)
    PP_cum=np.insert(PP_cum,0,0)
    ans=PP_cum[k:]-PP_cum[:n-k+1]
    print(np.max(ans))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n,k=map(int,input().split())
    P=[int(_) for _ in input().split()]
    PP=[0]*n
    for i in range(n):
        PP[i]=(P[i]+1)/2
    PP_ac=list(accumulate(PP))
    ans=PP_ac[k-1]
    for i in range(1,n-k+1):
        ans=max(ans,PP_ac[i+k-1]-PP_ac[i-1])
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc154/tasks/abc154_d"

def search_ind(lis, k):
    tmp = sum(lis[0:k])
    m = tmp
    inds = [0, k - 1]
    for i in range(0, len(lis) - k):
        tmp = tmp - lis[i] + lis[i + k]
        # print(tmp, lis[i + k])
        if tmp > m:
            inds = [i + 1, i + k]
            m = tmp
    return inds

def main():
    n, k = list(map(int, input().split()))
    daice = list(map(int, input().split()))
    f, t = search_ind(daice, k)
    kitai = daice[f:t + 1]
    ans = 0
    for v in kitai:
        sumt = 0
        for i in range(1, v + 1):
            sumt += i * (1 / v)
        ans += sumt
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
table = [0.5+i*0.5 for i in range(1001)]
a = list(map(int, input().split()))

ans = sum([table[a[i]] for i in range(k)])
last = ans
for i in range(1, n-k+1):
    last = last - table[a[i-1]] + table[a[i+k-1]]
    ans = max(last, ans)
print(ans)

Submission status: Accepted

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

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

ev_list =  np.array((p_list+1)/2)

max_num = sum(ev_list[0:K])
tmp = sum(ev_list[0:K])

for i in range(N-K):
    tmp = tmp - ev_list[i] + ev_list[i+K]
    if tmp > max_num:
        max_num = tmp

print(max_num)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
new_li = [0]
for l in li:
    new_li.append(new_li[-1]+(l+1)/2)
# print(new_li)
# [0, 1.0, 2.5, 4.0, 6.5, 9.5]
tmp_li = []
for i,n in enumerate(new_li):
    if i < k-1:
        continue
    tmp_li.append(new_li[i] - new_li[i-k])
    #print(i,i-k)
print(max(tmp_li))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
rui = [0]*(N+1)
for i in range(1,N+1):
    rui[i] = rui[i-1] + l[i-1]
maxwa = 0
for i in range(N-K+1):
    wa = rui[K+i]-rui[i]
    maxwa = max(maxwa,wa)
print((maxwa+K)/2)

Submission status: Accepted

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

q = []
for i in range(n):
    q.append((p[i] + 1) * 0.5)
maxv = 0
for i in range(k):
    maxv += q[i]
cnt = maxv
for i in range(n):
    if i + k >= n:break
    cnt = cnt - q[i] + q[i + k]
    maxv = max(cnt, maxv)
print(maxv)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

num = sum(num_li[:k])
ans = num
for j in range(n-k):
    num = num - num_li[j] + num_li[j+k]
    ans = max(num,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ika tako
n, k = map(int, input().split())
ppp = list(map(int, input().split()))
tot = sum(ppp[:k])#まず、先頭K個の合計を求める
ans = tot#仮の答としておく
for i in range(k, n):#for文で0-indexでk+1番目から最後までチェック
    tot += ppp[i] - ppp[i - k]#新しくi番目を足して、一番古いものを引く
    ans = max(ans, tot)#新しい答が大きいなら更新する
print((ans + k) / 2)#K個分のサイコロの期待値を出力する

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#入力
#n≦2*10^5
n, k = map(int, input().split())
P = list(map(int, input().split()))

def expectations(d:int)->float:
    return (d+1) / 2
E = list(map(expectations, P))  #Expectations list O(n)

tmp = sum(E[:k])    #temporary
ans = tmp 
for i in range(n-k+1):
    if ans < tmp:
        ans = tmp 
    else:
        pass
    if i == n-k:
        pass
    else:
        tmp -= E[i]
        tmp += E[k+i]
print(ans)