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:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, K = iim()
    P = list(iim())
    P2 = list(map(lambda x: x * (x + 1) / x / 2, P))

    ip = enumerate(P2)
    val = ans = 0
    for i in range(K-1):
        j, p = next(ip)
        val += p

    for i, p in ip:
        val += p
        if val > ans:
            ans = val
        #print(i, K, p, val, ans, i-K+1)
        val -= P2[i-K+1]
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

s = sum((1 / a[i]) * (a[i] * (a[i] + 1) // 2) for i in range(k))

m = s

for i in range(k, n):
    s += (1 / a[i]) * (a[i] * (a[i] + 1) // 2)

    i -= k

    s -= (1 / a[i]) * (a[i] * (a[i] + 1) // 2)

    m = max(m, s)

print('%.12f'%m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n,k = (int(i) for i in input().split())  
# 空白区切りの数列をリストに代入
p = [int(i) for i in input().split()] 

q = [0]*(n-k+1)

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

for i in range(k,n):
    q[i-k+1] = q[i-k]+p[i]-p[i-k]
maxsum=0
for i in range(n-k+1):
    maxsum=max(maxsum,q[i])

print((maxsum+k)/2)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int, input().split())) 
ans0=sum(A[0:K])
ans=ans0
for i in range(0,N-K):
  ans=ans-A[i]+A[K+i]
  if ans>ans0:
    ans0=ans
    
ans=(ans0+K)*0.5
print(ans)

Submission status: Accepted

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

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

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

m = [0] * N
m[0] = sum(per[ : K])
for x in range(1, N - K + 1):
    m[x] = m[x - 1] - per[x - 1] + per[x + K - 1]


print(max(m))

Submission status: Accepted

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

Submission status: Accepted

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

print((k + m) / 2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
S = sum(P[:K])
M = S
for k in range(N - K):
    S = S - P[k] + P[k + K]
    if M < S:
        M = S
print((M + K)/2)

Submission status: Accepted

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

x = sum(l[:k])
max_val = x
for i in range(n-k):
    x = x-l[i]+l[i+k]
    if x > max_val:
        max_val = x

print((max_val+k)*1.0/2)

Submission status: Accepted

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

e=[0] #1000までの期待値
def calc(num):
    re=0
    kaku=1/num
    for i in range(1,num+1):
        re+=kaku*i
    return re
for i in range(1,1001):
    e.append(calc(i))
#pを期待値に置き換え    
for i in range(n):
    a=p[i]
    p[i]=e[a]
    
#累積和    
wa=[0,p[0]]
for i in range(1,n):
    wa.append(wa[i]+p[i])

ans=0
for i in range(1,n+1):
    s=i
    g=i+(k-1)
    if n<g:
        break
    now_=wa[g]-wa[s-1]
    if ans<now_:
        ans=now_
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = [(int(i)+1)/2 for i in input().split()]
max_p = 0
for n in range(N-K+1):
    if n == 0:
        temp = sum(P[0:K])
    else:
        temp -= P[n-1]
        temp += P[n+K-1]
    max_p = max(max_p,temp)
print(max_p)

Submission status: Accepted

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

def excepted_value(p):
    return p * (p+1) // 2

def solve(N, K, P):
    s = [0 for i in range(N+1)]
    for i in range(1, N+1):
        s[i] = s[i-1] + P[i-1]
    max_left_value = -1
    max_left_idx = -1
    for i in range(N+1-K):
        if s[i+K] - s[i] > max_left_value:
            max_left_value = s[i+K] - s[i]
            max_left_idx = i
    excepted_value_sum = 0.0
    for i in range(max_left_idx, max_left_idx+K):
        excepted_value_sum += float(excepted_value(P[i])) / P[i] 
    return excepted_value_sum


if __name__ == '__main__':
    inputs = read()
    print("%.8f" % solve(*inputs))

Submission status: Accepted

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

    temp = 0
    for k in range(K):
        temp += calc_e(p[k])
    res = temp
    for n in range(N-K):
        temp -= calc_e(p[n])
        temp += calc_e(p[n+K])
        if(temp > res): res = temp
    print(res)


def calc_e(pi):
    return(sum(range(1,pi+1))/pi)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,K = map(int,input().split())
p = np.array(list(map(int,input().split())))
e = (p+1) / 2.0
s = np.zeros(len(e)+1)
s[1:] = np.cumsum(e)
f = s[K:] - s[:-K]

print(np.max(f))

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
cal=lambda x:(1+x)/2
a=list(map(cal,a))
#print(a)
now=sum(a[:k])
ans=now
#print(now)
d=a[0]
for i in range(1,n-k+1):
    #print(i)
    tmp=now-d+a[i+k-1]
    ans=max(ans,tmp)
    d=a[i]
    now=tmp
    #print(now)
    #print()
print(ans)

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
p = list(map(int, input().split()))
# s = [0] + list(itertools.accumulate(p))
e = []

ans = 0
# temp = s[1]
l = 1
r = 1
# prev =

def getExp(n):
    return (n*(n+1)/2) / n

for i in range(n):
    e.append(getExp(p[i]))

s = [0] + list(itertools.accumulate(e))

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

# print(s)
# print(e)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
kitai=[0]
for i in range(1,1001):
    tmp=0
    d=1/i
    for j in range(1,i+1):
        tmp+=j*d
    kitai.append(tmp)
#print(kitai[:10])
ac=[0]
for i in a:
    ac.append(ac[-1]+kitai[i])
#print(ac)
ans=0
for i in range(k-1,n+1):
    ans=max(ans,ac[i]-ac[i-k])
print(ans)

Submission status: Accepted

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


def kitai(i: int) -> int:
    if i % 2:
        return ((1 + i) * (i // 2) + (i // 2) + 1) / i
    else:
        return ((1 + i) * (i // 2)) / i


kitai_dict = dict()
kitai_list = list()

for i in range(n):
    if a[i] in kitai_dict:
        kitai_list.append(kitai_dict[a[i]])
    else:
        kitai_dict[a[i]] = kitai(a[i])
        kitai_list.append(kitai_dict[a[i]])

current_sum = sum(kitai_list[:k])
ans = current_sum
for i in range(k, n):
    current_sum += kitai_list[i]
    current_sum -= kitai_list[i - k]
    ans = max(ans, current_sum)

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
cnt=sum(p[0:k])
ans=[]
ans.append(cnt)
for i in range(n-k):
    cnt=cnt-p[i]+p[i+k]
    ans.append(cnt)



print(max(ans))

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,K = imn()
p = iln()

ans = 0
total = 0
c = [0 for _ in range(N+1)]
for i in range(N):
    c[i] = ((p[i] * (p[i] + 1)) // 2 / p[i])
    total += c[i]
    if i+1 >= K:
        ans = max(ans, total)
        total -= c[i-K+1]
print(ans)

Submission status: Accepted

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

max_s = sum(p[0:K])
s = sum(p[0:K])
for i in range(N-K):
    f = p[K+i]
    b = p[i]
    ns = s + f - b
    if ns >= max_s:
        max_s = ns
    s = ns
    # print(s)

print((K+max_s)/2)

Submission status: Accepted

Solution code:
x = list(map(int, input().split()))
y = list(map(int, input().split()))
y = [i/2+0.5 for i in y]
max_value = 0
value = sum(y[:x[1]])
for i in range(x[1], x[0]):
  max_value = max(max_value, value)
  value += y[i]
  value -= y[i-x[1]]
max_value = max(max_value, value)
print(max_value)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import deque

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

    dq = deque()
    maxnum = None
    total = None

    for idx, p in enumerate(ps):
        dq.append(p)

        if len(dq) == K:
            total = sum(dq)
            maxnum = total

        if len(dq) > K:
            popnum = dq.popleft()
            total -= popnum
            total += dq[-1]
            if total > maxnum:
                maxnum = total

    exp = (maxnum + K) / 2.0
    print(exp)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


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

def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

c = cumsum(k)
c = [0] + c
ans = 0

for i in range(N-K+1):
    t = c[i+K] - c[i]

    if t > ans:
        ans = t

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

pi={}
pi[0]=0
pi[1]=1
for i in range(2,1002):
    pi[i]=pi[i-1]+i
    pi[i-1]=pi[i-1]/(i-1)

temp=0
for i in range(k):
    temp+=pi[p[i]]
    #print("start",temp)



#print(temp)
result=temp

for i in range(k,n):
    temp=temp-pi[p[i-k]]+pi[p[i]]
    #print(temp)
    result=max(result,temp)
print(result)

Submission status: Accepted

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

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

s = sum(P[:K])
m = s

for i, p in enumerate(P[K:]):
    s = s + p - P[i]
    m = max(m, s)


print('{:.9f}'.format((m+K)/2))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
total = 0
saidai = -9999
ans = 0
B = [0]*(len(A)+1)
for i in range(len(A)):
    total += A[i]
    B[i+1] = total
for j in range(N-K+1):
     if B[j+K]-B[j]>saidai:
            saidai = B[j+K]-B[j]
            P = A[j:j+K]
for i in range(len(P)):
    ans += (0.5*P[i]*(P[i]+1))/P[i]
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from itertools import accumulate
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,K=LI()
acc = LI()
for i in range(N):
    acc[i] = (1+acc[i]) / 2
acc2 = list(accumulate(acc))
# print(acc)
# print(acc2)

res = acc2[N-1] if K == N else 0
for i in range(1, N-K+1):
    if i == 1:
        res = acc2[K-1]
    else:
        res = max(res, acc2[i+K-1] - acc2[i-1])
    # print(i-1, i+K-1)

print(res)

Submission status: Accepted

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

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

sum_p_max = sum(p[0:K])
sum_i = sum(p[0:K])

for i in range(1, N-K+1):
    sum_i += p[i+K-1] - p[i-1]
    if sum_p_max < sum_i:sum_p_max = sum_i
print((sum_p_max+K)/2)

Submission status: Accepted

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

dat2 = []
m = -1
#print(dat[:k])
n = sum(dat[:k])
dat2.append(n)
m = n
mind = 0
for i in range(1, len(dat) - k ):
    #print("in/out")
    #print(dat[k+i])
    #print(dat[i])
    n += dat[k+i]
    n -= dat[i]
    dat2.append(n)
    if n > m:
        m = n
        mind = i + 1


#print(dat2)
#print(m)
#print(mind)

r = 0
for i in range(mind, mind + k):

    r += (dat[i] + 1) / 2

print(r)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import accumulate

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

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

    p = [0] + list(accumulate(p))

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
dice = list(map(int, input().split()))
ma = 0
kitai = [0]*N
for i in range(N):
    kitai[i] = (((dice[i]+1)*dice[i])/2)/dice[i]
for i in range(K):
    ma += kitai[i]
tmp = ma
for i in range(K,N):
    tmp = tmp - kitai[i-K] + kitai[i]
    ma = max(tmp,ma)
print(ma)

Submission status: Accepted

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

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

cnt = 0
dice = [(i+1)/2 for i in p]

ans = sum(dice[:k])
exp = sum(dice[:k])

for i in range(k, n):
    exp = exp-dice[i-k]+dice[i]
    ans = max(ans, exp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

e = [0 for i in range(n)]
_e = 0

for i in range(n):
  _e += (p[i] + 1) / 2
  if i >= k:
    _e -= (p[i - k] + 1) / 2
  e[i] = _e

print(max(e))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
pp=[]
su=0
for i in range(n):#累積和
    if i<k:
        su+=p[i]
    else:
        pp.append(su)
        su=su-p[i-k]+p[i]
pp.append(su)
ans=0.0
for i in range(len(pp)):
    j=(pp[i]+k)/2
    if ans<j:
        ans=j
print(ans)

Submission status: Accepted

Solution code:
class NumArray:
    def __init__(self, nums):
        if len(nums)>0:
            self.length = len(nums)
            self.tree = [0 for _ in range(2*self.length)]
            
            # build tree 
            n = self.length
            i = n
            j = 0
            while i<2*n:
                self.tree[i] = nums[j]
                i += 1
                j += 1
            for i in range(n-1, 0, -1):
                self.tree[i] = self.tree[i*2] + self.tree[i*2 + 1]

    def update(self, pos, val):
        # 0 <= pos < n
        n = self.length
        pos += n
        self.tree[pos] = val
        while (pos > 0):
            left = pos
            right = pos
            if pos%2==0:
                right = pos + 1
            else:
                left = pos - 1
            self.tree[pos//2] = self.tree[left] + self.tree[right]
            pos //= 2
        
    def sumRange(self, l, r):
        if l > r:
            l, r = r, l
        # 0 <= l,r < n
        n = self.length
        l += n
        r += n
        res = 0
        while l<=r:
            # check l is right child
            if l%2==1:
                res += self.tree[l]
                l += 1
            # check r is left child
            if r%2==0:
                res += self.tree[r]
                r -= 1
            l //= 2
            r //= 2
        return res
       


N, K = list(map(int, input().split()))
arr = list(map(int, input().split()))
seg_sum_tree = NumArray(arr)

mx_sum = 0
idx = 0
for i in range(N):
    if N <= i + K - 1:
        break
    val = seg_sum_tree.sumRange(i, i+K-1)
    if mx_sum <= val:
        mx_sum = val
        idx = i

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
l = []
maxe = 0
e = 0
for i in range(N):
    l.append((p[i]+1)/2)

for i in range(K-1):
    e += l[i]

for i in range(K-1,N):
    e += l[i]
    if (maxe < e):
        maxe = e
    e -= l[i-K+1]

print(maxe)

Submission status: Accepted

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

s = []
for i in range(K):
    s.append(p[i])

m = sum(s)
t = m
for i in range(K, N):
    t += p[i] - p[i - K]
    if m < t:
        m = t

m += K

print(m / 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
Es = [n * (n + 1) / 2 / n for n in P]

res = sum(Es[0:K])
now = res
for i in range(0, N-K):
    now = now - Es[i] + Es[i+K]
    res = max(res, now)

print(res)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
pp = []
total = 0
for i in range(1, 1001):
    total += i
    pp.append(total/i)
p = [pp[i-1] for i in p]
ans = sum(p[:K])
total = ans
for i in range(N - K):
    total -= p[i]
    total += p[i+K]
    ans = max(ans, total)
print(ans)

Submission status: Accepted

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

e = [0] * N

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

total = sum(e[0:K])
ans = total

for i in range(N - K):
    total += e[i + K] - e[i]
    if total > ans:
        ans = total

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] * (p[i] + 1) / 2 / p[i]
    if i != 0:
        p[i] += p[i - 1]

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, K = map(int, input().split())
P = np.array(input().split(), dtype=int)
# 期待値に変換
Q = P/2 + 0.5
# 累積和をとる
S = Q.cumsum()
# K範囲での最大値
if N == K:
    print(S[-1])
else:
	T = S[K:] - S[:-K]
	print(max(T))

Submission status: Accepted

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

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

    total = 0
    m = 0
    for i in range(N):
        if i < K:
            total += E[i]
        else:
            total += E[i] - E[i - K]

        if total > m:
            m = total

    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

ttl = 0
for i in range(K):
    d = l[i]
    ttl += (d+1)/2
M = ttl

for i in range(K,N):
    st = i-K
    d = l[st]
    ttl -= (d+1)/2
    dd = l[i]
    ttl += (dd+1)/2
    M = max(ttl,M)
print(M)

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
S = [0, ]
for i in range(1, 1001):
    S.append(S[-1]+i)
E = [s/(i+1) for i, s in enumerate(S[1:])]
E = [0, ] + E

ans = 0
before_ans = 0
for i, p in enumerate(P):
    #print(ans, before_ans)
    if i < K:
        ans += E[p]
        before_ans = ans - E[P[i-K+1]]
        continue
    tmp_ans = before_ans + E[p]
    ans = max(tmp_ans, ans)
    before_ans = tmp_ans - E[P[i-K+1]]
print(ans)

Submission status: Accepted

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

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

sum = 0

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

max_sum = sum

for i in range(n-k):
    sum -= ave(p[i])
    sum += ave(p[i+k])
    max_sum = max(sum, max_sum)

print(max_sum)

Submission status: Accepted

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

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

t = sum(p[:K])
m = (t + K) / 2
for i in range(1, N - K + 1):
    t = t - p[i - 1] + p[i + K - 1]
    m = max(m, (t + K)/2)

print(m)

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
  
num = sum(p[:k])
max_num = num

for i in range(k,n):
  num = num - p[i-k] + p[i]
  max_num = max(max_num, num)
  
  
print(max_num)

Submission status: Accepted

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

expect_list = [((1+yokolist[i])/2) for i in range(n)]

#print(expect_list)

answer = 0
l = expect_list[0:k]
p = sum(l)
for j in range(n-k+1):
    if p > answer:
       answer = p
    if j != n-k:
        p = p - expect_list[j] + expect_list[k+j]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N, K = map(int, input().split())
P = list(map(int, input().split()))
acc = [0]

def calc(n):
  num =  n * (n+1) / 2
  return num / n

tmp = 0
for p in P:
  num = calc(p)
  tmp += num
  acc.append(tmp)

left = 0
right = K 
ans = 0

while right <= N:
  ans = max(ans, acc[right] - acc[left])
  left += 1
  right += 1

print(ans)

Submission status: Accepted

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

a = sum(p[0:k])
m = a
o = 0
for i in range(n - k):
    a += p[i + k] - p[i]
    #print(i, p[i + k], p[i], a)
    if a > m:
        m = a
        o = i + 1
'''
q = []
for i in range(n):
    q.append((p[i] + 1) / 2)
'''
ans = 0
#for i in range(k - 1, n):
#tmp = 0
for j in range(o, o + k):
    ans += (p[j] + 1) / 2

print(ans)

Submission status: Accepted

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


def solve(N: int, K: int, p: "List[int]"):
    kitai=[0]*N
    for i in range(N):
        kitai[i]=(p[i]+1)/2

    ss=sum(kitai[0:K])
    ssmax=ss
    for i in range(N-K):
        ss-=kitai[i]
        ss+=kitai[i+K]
        if ssmax<ss:
            ssmax=ss

    print(ssmax)
    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:
N,K=map(int,input().split())
plist=list(map(int,input().split()))

exp_list=[]
for p in plist:
  exp_list.append((p+1)/2.0)

#print(exp_list)
part_sum=sum(exp_list[:K])
ps_list=[part_sum]
for i in range(K,N):
  part_sum+=exp_list[i]-exp_list[i-K]
  ps_list.append(part_sum)
  
#print(ps_list)
print(max(ps_list))

Submission status: Accepted

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

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

fir = 0
nex = k
num = sum(exp[:nex])
ma = 0
while nex <= n:
	if ma < num:
		ma = num
	if nex < n:
		num -= exp[fir]
		num += exp[nex]
		fir += 1
		nex += 1
	else:
		break
print(ma)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

foo = sum(P[0:K])
ans = foo
for i in range(K,N):
    foo += P[i] -P[i-K]
    if ans < foo:
        ans = foo
print((ans+K)/2)

Submission status: Accepted

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

sm = [0, P[0]]
for pi in P[1:]:
    x = sm[-1] + pi
    sm.append(x)

# print(sm)

mx = 0
mxi = 0
for i in range(N-K+1):
    x = sm[i+K] - sm[i]
    # print(i, x)
    if x > mx:
        mx = x
        mxi = i

# print(mx, i)

ans = 0
for i in range(K):
    p = P[mxi+i]
    # print('p', p)
    ans += ((1 + p) * p / 2) / p
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

RUISEKI_A=[0]
for a in A:
    RUISEKI_A.append(RUISEKI_A[-1]+a)

ans=float("-inf")
for i in range(N-K+1):
    ans=max(ans,RUISEKI_A[i+K]-RUISEKI_A[i])

print ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
d = {}
for i in range(1,200001):
  d[i] = (1+i)/2

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

ans_ = ans
for i in range(n-k):
  ans_ = ans_ - d[p[i]] + d[p[k+i]]
  if ans_ > ans:
    ans = ans_
print(ans)

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 += (1+p[i])*p[i]/2/p[i]

ans_ = ans

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


print(ans)

Submission status: Accepted

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

def expec(n):
    return ((1/2 * n * (n+1) )/ n)

def maxSum(arr, n, k): 
    res = 0
    for i in range(k): 
        res += expec(arr[i])
    curr_sum = res 
    for i in range(k, n):       
        curr_sum += expec(arr[i]) - expec(arr[i-k])
        res = max(res, curr_sum) 
    return res 
  
print(maxSum(p, N, K))

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
a = [0] + map(int, raw_input().split())
for i in xrange(1, len(a)):
    a[i] += a[i - 1]
print (k + max(a[i] - a[i - k] for i in xrange(k, len(a)))) / 2.0

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
tmp = []
t = 0
for i in a:
    t += (1/2) * (i+1)
    tmp.append(t)

mx = tmp[m-1]
for i in range(n-m):
    mx = max(mx, tmp[m+i]-tmp[i])
    #print(tmp[m+i], tmp[i])
print(mx)

Submission status: Accepted

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

tab1 = [0]
tab1_tmp = 0
for pi in range(1, max(p) + 1):
    tab1_tmp += pi
    tab1.append(tab1_tmp)
# print("#", tab1)

tab2 = [0]
for i in range(N):
    tab2.append(tab1[p[i]] / p[i])
# print("#", tab2)

tab3 = [0]
tab3_tmp = 0
for i in range(1, N + 1):
    tab3_tmp += tab2[i]
    tab3.append(tab3_tmp)
# print("#", tab3)

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

Submission status: Accepted

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

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

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

import itertools
cumsum = list(itertools.accumulate(p))
cumsum = [0] + cumsum
ans = []

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

print(max(ans))

Submission status: Accepted

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

m_r = sum(p[:K])
m_max = m_r

for i in range(N - K):
    m_r -= p[i]
    m_r += p[i + K]
    if m_max < m_r:
        m_max = m_r

print(m_max / 2)