Problem:


Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000



Sample input:
5 3
1 2 2 4 5


Sample output:
7.000000000000

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = list(map(int,input().split()))
# print(p)
a = [0]
for pi in p:
	a.append(a[-1] + (1 + pi) / 2)
# print(a)
l = [a[i + K] - a[i] for i in range(N - K + 1)]
ans = max(l)
print(ans)

Submission status: Accepted

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

*ev, = map(lambda x: (x*(x+1)/2)/x, p)
cusum = [0]*(n+1)
for i in range(n):
    cusum[i+1] = cusum[i] + ev[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

max_sub = sum(P[0:K])
sub = max_sub
l = 0

for n in range(N-K):
    sub += P[n+K] - P[n]

    if max_sub < sub:
        max_sub = sub
        l = n + 1

print((sum(P[l:l+K])+K) / 2)

Submission status: Accepted

Solution code:
from itertools import accumulate
n, k = map(int,input().split())
P = list(map(lambda x:(int(x)+1)/2,input().split()))
A = list(accumulate([0]+P))
B = []
for i in range(n-k+1):
    B.append(A[i+k]-A[i])

print(max(B))

Submission status: Accepted

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

import numpy as np

max_v = np.sum(P[:k])

#print(max_v)
j = 0
cum = 0

temp_max = max_v

for i in range(k, n):
  temp_max += P[i]
  temp_max -= P[i-k]
  if temp_max>max_v:
    max_v = temp_max
    j=i-k
              
ans = (max_v+k)/2
print(ans)
#print(max_v)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
P=[(float(x)+1)/2 for x in input().split()]
#print(P)
max=0
kitai=0
for i in range(K):
    kitai+=P[i]
max=kitai
for i in range(N-K):
    kitai-=P[i]
    kitai+=P[i+K]
    if max<kitai:
        max=kitai
print(max)

Submission status: Accepted

Solution code:
from collections import deque

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

exps = [-1.0] * 1001
seed = 0
for i in range(1, 1001):
    seed += i
    exps[i] = seed / i

total = 0
heads = deque()
for k in range(K):
    p = P[k]
    exp = exps[p]
    total += exp
    heads.append(exp)
ans = total
for k in range(K, N):
    exp = exps[P[k]]
    head = heads.popleft()
    heads.append(exp)
    total = total - head + exp
    ans = max(ans, total)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
li = list(map(int,input().split()))
ruisekiwa = list(np.cumsum(li))
ruisekiwa.insert(0,0)
ans = []
for i in range(n-k+1):
  num = ruisekiwa[i+k]-ruisekiwa[i]
  ans.append(num)
print(0.5*max(ans) + 0.5*k)

Submission status: Accepted

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

Submission status: Accepted

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

sum_memo = [0]*1001
x_memo = [0] * 1001
x_list = [0]*N

for i in range(1,1001):
    sum_memo[i] = sum_memo[i-1] + i

for i in range(N):
    if x_memo[p[i]] == 0:
        x_memo[p[i]] = sum_memo[p[i]]/p[i]
    x_list[i] = x_memo[p[i]]


ans = 0
tmp = sum(x_list[:K])
#print(tmp)
#print(x_list)
if N==K:
    print(tmp)
    exit()
for l in range(N-K):
    r = l+K
    tmp = tmp -  x_list[l] + x_list[r]
#    print(l,r,x_list[l], x_list[r], tmp)
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
def maxSum(arr, n, k): 
   
    res = 0.0
    for i in range(k): 
        res += arr[i] 
  
    curr_sum = res 
    for i in range(k, n): 
      
        curr_sum += arr[i] - arr[i-k] 
        res = max(res, curr_sum) 
  
    return res 
  
n,k = map(int,input().split())
a = list(map(int,input().split()))
ep = []
for i in range(n):
    p = a[i]
    ep.append((1/p)*((p*(p+1))//2))
print ("{0:.15f}".format(maxSum(ep,n,k)))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
L=list(map(int,input().split()))
A=[0]*N


for i in range(N):
    t=(L[i]+1)*L[i]/2*(1/L[i])
    A[i]=t
s=0
t=sum(A[:K])
s=max(s,t)
for i in range(N-K):
    t+=(A[i+K]-A[i])
    s=max(s,t)

print(s)

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, K = map(int, f_i.readline().split())
    p = tuple(map(int, f_i.readline().split()))
    
    idx = 0
    max_s = sum(p[:K])
    s = max_s
    for i, t in enumerate(zip(p, p[K:]), start=1):
        pi, pj = t
        s += (pj - pi)
        if s > max_s:
            max_s = s
            idx = i
    
    ans = (sum(p[idx:idx+K]) + K) / 2
    
    print(ans)

solve()

Submission status: Accepted

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

def expectation(pp):
    return 1 + (0.5 * (pp - 1))

p = list(map(int, input().split()))
ep = tuple(map(expectation, p))

cum = [0]
cum_append = cum.append
for i in range(N):
    cum_append(cum[i] + ep[i])

result = 0

for i in range(0, N - K + 1):
    tmp = cum[i + K] - cum[i]
    result = max(result, tmp)
    
print(result)

Submission status: Accepted

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

t = [0]*n
for j in range(k):
    t[0] += p[j]
for i in range(1,n-k+1):
    t[i] = t[i-1]-p[i-1]+p[i+k-1]
T = t.index(max(t))
ans = 0
for i in range(k):
    ans += (p[T+i]+1)/2
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    pp = list(map(int, input().split()))
    i = 0
    maxi = 0
    s = sum(pp[maxi:maxi + k])
    maxs = s
    while i < n - k:
        s = s - pp[i] + pp[i + k]
        if maxs < s:
            maxs = s  # 増加しているなら
            maxi = i + 1
        i += 1
    print((sum(pp[maxi:maxi + k]) + k) / 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    strings = input().split(' ')
    N = int(strings[0])
    K = int(strings[1])
    p_raw = input().split(' ')
    exp = []
    for i in p_raw:
        exp.append((int(i)+1)/2.)
    max = 0
    exp_prev = sum(exp[0:0 + K -1])
    for i in range(N-K+1):
        
        sum_exp = exp_prev + exp[i + K-1]
        exp_prev = sum_exp - exp[i]
        if sum_exp > max:
            max = sum_exp
            
    
    print(max)
    return 0

main()

Submission status: Accepted

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

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

print(sum([(1+n)/2 for n in max_num]))

Submission status: Accepted

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

pls = [0.0 for _ in range(n+1)]

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

ans = 0

for i in range(n-k+1):
    if pls[i+k]-pls[i] > ans:
        ans = pls[i+k]-pls[i]
print(ans)

Submission status: Accepted

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

s=(sum(P[:K])+K)/2
ans=s

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

Submission status: Accepted

Solution code:
import numpy as np
N,K=map(int,input().split())
p=list(map(int,input().split()))
p=np.array(list(map(lambda x: (1+x)/2, p)))
mx_0 = np.sum(p[:K])
mx=0
#print(p)
if N!=K:
  for i in range(1,N-K+1):
    s = mx_0-p[i-1]+p[i+K-1]
    mx_0=s
    #print(s)
    mx = max(s,mx)
else:
  mx=np.sum(p)
  
print(mx)

Submission status: Accepted

Solution code:
import numpy as np
N,K=list(map(int, input().split())) 
P =list(map(int, input().split())) 
am = np.cumsum(list(range(1, 1000+1)))
e = [am[P[i]-1] / P[i] for i in range(N)]
e_sum = np.cumsum(e)
ans = 0
for i in range(K-1, N):
  if(i == K-1):
    ans = e_sum[i]
  else:
    ans = max([ans, e_sum[i] - e_sum[i-K]])
print(ans)

Submission status: Accepted

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

count = 0
val = sum(p[0:k])
val_lis = [val]
mx_val = val
index = 0
mx_index = 0
for i,j in enumerate(p[k:]):
    val = val - p[index] + j
    val_lis.append(val)
    index +=1
    if val > mx_val:
        mx_index = index
        mx_val = val 
    
ans = 0
for i in range(k):
    ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
#a=[(1+i)/2 for i in a]
import itertools
ac=itertools.accumulate(a)
ac=list(ac)

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

print((ans+k)/2)

Submission status: Accepted

Solution code:
N,K = [int(x) for x in input().split()]
ps = [int(x) for x in input().split()]
best_val = 0
past_val = None
for i in range(K-1, N):
    if past_val is None:
        past_val = (sum(ps[i + 1 - K:i + 1]) + K) / 2
    else:
        past_val += (ps[i] - ps[i - K]) / 2
    val = past_val 
    if best_val < val:
        best_val = val 
print(best_val)

Submission status: Accepted

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


tmp=sum(p[0:k])
Msum=tmp

for i in range(1,n-k+1):
    a=p[i-1]
    b=p[i+k-1]
    tmp=tmp-a+b
    Msum = max(tmp,Msum)

print((Msum+k)/2)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
d = 0
e = []

for i in range(len(b)):
    d = d + b[i]
    c.append(d)

for i in range(len(b) - K):
    e.append(c[i + K] - c[i] + K)
if N==K:
    print((sum(b) + K)/2)
else:    
    print(max(e)/2)

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
A = 0
for i in range(K):
    A = A+P[i]
    B = A
for i in range(1,N-K+1):
    B = B-P[i-1]+P[i+K-1]
    if A < B:
        A = B
print(A)

Submission status: Accepted

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

cursum = sum(ps[:K])
l = 0
h = K
i = 0
best = cursum
while h != N:
    cursum += ps[h] - ps[l]
    h += 1
    l += 1
    if (cursum > best):
        best = cursum
        i = l

ans = 0
for j in range(K):
    ans += (ps[i+j] + 1) / 2 
print(ans)

Submission status: Accepted

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

S=[0]*(n+1)
S[1]=P[0]
for i in range(2,n+1):
        S[i]=S[i-1]+P[i-1]
ma=0
for i in range(k,n+1):
       s=S[i]-S[i-k]
       if ma<s:
              ma=s
print((ma+k)/2)

Submission status: Accepted

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

def main(N, K, P):
    S = [0] * N
    E = [0] * N
    for i in range(N):
        n = P[i]
        S[i] = n * (n+1)/2/n
    if K == N:
        return sum(S)
    a = 0
    E[K-1] = sum(S[:K])
    for i in range(K, N):
        E[i] = E[i-1] - S[i-K] + S[i]
        a = max(a, E[i])
    return a
print(main(N, K, P))

Submission status: Accepted

Solution code:
# D

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

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

ans = (ans+K)/2

print(ans)

Submission status: Accepted

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

    right = K
    left = 0
    mx = 0
    for p in P[left:right]:
        mx += getExpected(p)
    now = mx

    while right < N:
        now = now - getExpected(P[left]) + getExpected(P[right])
        
        mx = max(now,mx)
        left += 1
        right += 1
    
    print(mx)

def getExpected(n):
    retval = 0
    for i in range(1,n+1):
        retval += (1/n) * i
    return retval

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

e = 0.0
for i in range(K):
    e = e + (p[i] + 1) / 2.0

emax = e
for i in range(K,len(p)):
    e = e - (p[i-K] + 1) / 2.0 + (p[i] + 1) / 2.0
    if emax < e:
        emax = e

print(emax)

Submission status: Accepted

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

for i in range(n):
    if p[i] % 2 == 0:
        p[i] = (p[i] + 1) * (p[i] / 2) /p[i]
    else:
        p[i] = ((p[i] + 1) * math.floor(p[i] / 2) + math.ceil(p[i] / 2))  /p[i]

tmp = 0
for j in range(k):
    tmp = tmp + p[j]

max = tmp

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

print(max)

Submission status: Accepted

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

print(max(convert))

Submission status: Accepted

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

max_set = sum(p[:k])
pair = sum(p[:k])
for i in range(n-k):
    pair -= p[i]
    pair += p[i+k]
    if max_set < pair:
        max_set = pair

print((max_set+k)/2)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import accumulate


def main():
    input = lambda: stdin.readline()[:-1]
    N, K = map(int, input().split())
    P = map(int, input().split())

    num = [0] * (N + 1)
    for i, j in enumerate(P, start=1):
        num[i] = ((j * (j + 1)) // 2) / j
    num = list(accumulate(num))
    ans = 0
    for i in range(K, N + 1):
        ans = max(ans, num[i] - num[i-K])
    print(ans)


main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
maxim=[0]*(n-k+1)
cnt=0
s=0
for i in range(n):
    cnt+=1
    s+=p[i]
    if cnt==k:
        maxim[i-(k-1)]=s
        cnt=k-1
        s+=-p[i-(k-1)]

ans=(max(maxim)+k)/2
print(ans)

Submission status: Accepted

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

if n != k:
    memo = [0] * (n + 1)

    for i in range(n):
        memo[i] = memo[i - 1] + p[i]

    ans = 0
    for i in range(k, n):
        ans = max(ans, memo[i] - memo[i - k])

    ans = (ans + k) / 2
    print(ans)
else:
    ans = (sum(p) + k) / 2
    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()))
Ans = sum(P[0:K])+K
Ans_max = Ans

for i in range(0,N-K):
    A = P[i]
    B = P[i+K] 
    Ans = Ans+B-A
    if B > A:
        Ans_max = max(Ans_max, Ans)
    
print(Ans_max/2)

Submission status: Accepted

Solution code:
import numpy as np
N,K=list(map(int,input().split()))
p=list(map(int,input().split()))
p=list(map(lambda x:(x+1)/2, p))
p_cs=[0]
p_cs.extend(np.cumsum(p))
max_exp=0
for i in range(N-K+1):
  exp=p_cs[i+K]-p_cs[i]
  if exp>max_exp:
    max_exp=exp
print(max_exp)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(float,input().split()))
x=[0.0]*n
for i in range(n):
	x[i]=(p[i]*(p[i]+1)/2)/p[i]
v=[0.0]*(n-k+1)
for i in range(n-k+1):
	if(i!=0):
		v[i]=v[i-1]-x[i-1]+x[i+k-1]
	else:
		for j in range(k):
			v[0]+=x[i+j]
print(max(v)+0.000000001)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

s = np.cumsum(p)
# print(p, s)

m = []


def partsum(s, x):
    global K
    if x == K - 1:
        return s[x]
    return s[x] - s[x - K]


for i in range(K - 1, N):
    m.append(partsum(s, i))
# print(m)

idx = m.index(max(m))
# print(idx)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def e(a,b):
    x=(a+b)/2
    return x
ans=0
Max=0
n,k=map(int,input().split())
l=list(map(int,input().split()))
tmp=0
for i in range(k):
    Max+=l[i]
tmp=Max
for j in range(k,n):
    tmp+=l[j]
    tmp-=l[j-k]
    Max=max(tmp,Max)
print(e(Max,k))

Submission status: Accepted

Solution code:
import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    if i != 0:
        kakuritsu[i] = kakuritsu[i-1] + ( num_list[pn[i]] / pn[i] )
    else:
        kakuritsu[i] = num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    if i != 0:
        max_sn[i] = ( kakuritsu[i-1+K] - kakuritsu[i-1]   ) * (-1)
    else:
        max_sn[i] = kakuritsu[i-1+K] * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
d = [0 for _ in range(n)]

for i in range(len(p)):
    p[i] = 0.5*(p[i]+1)
d[0] = sum(p[0:k])
for i in range(1, n-k+1):
    d[i] = d[i-1] + p[i+k-1] -p[i-1]
print(max(d))

Submission status: Accepted

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

Submission status: Accepted

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

exarr = [(i+1)/2 for i in arr]
tmpsum = sum(exarr[:k])
sol = tmpsum

for i in range(n-k):
    tmpsum = tmpsum - exarr[i] + exarr[i+k]
    sol = max(sol,tmpsum)
    
print(sol)

Submission status: Accepted

Solution code:
import math
import calendar
import fractions
import itertools

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

ans_list = []

for i in p:
    if i % 2 == 0:
        ans_list.append(i / 2 + 0.5)
    else:
        ans_list.append(i // 2 + 1)


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

Submission status: Accepted

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



def E(x):
    # ans = 0
    tmp = (x*(x+1))/2 if x % 2 == 0 else x+(((x-1)*(x))/2)
    return tmp/x
ans = 0
for i in range(len(P)):
    P[i] = round(E(P[i]),1)
max_v = tmp = sum(P[:k])
l = 0
r = k
for i in range(1,len(P)-k+1):
    tmp = tmp-P[i-1]+P[r]
    max_v = max(max_v, tmp)
    r += 1
print(max_v)

Submission status: Accepted

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

ans = 0
tmp = 0
for i in range(k):
    tmp += (p[i]+1)/2
ans = tmp
for i in range(1, n-k+1):
    tmp += -(p[i-1]+1)/2 + (p[i+k-1]+1)/2
    if(ans < tmp):
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
n, k, *ps = map(int, open(0).read().split())
dp = tmp = sum(ps[:k])
for i in range(1,n-k+1):
  tmp = tmp - ps[i-1] + ps[i+k-1]
  dp = max(dp, tmp)
print((dp+k)/2)

Submission status: Accepted

Solution code:
i1 = input()

n = int(i1.split(' ')[0])
k = int(i1.split(' ')[1])

i2 = input()
p = i2.split(' ')

m_l = 0
for nn in range(0, k):
    m_l += int(p[nn])
m = m_l
for nn in range(k, n):
    m += -int(p[nn-k])+int(p[nn])
    if(m_l < m):
        m_l = m

print((m_l + k)/2)

Submission status: Accepted

Solution code:
from functools import lru_cache

def pleaseAC(ary):
    v = 0
    for i in ary:
        v += kitaichi(i)
    return v

@lru_cache(maxsize=1001)
def kitaichi(n):
    return sum(range(1,n+1)) / n

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


    best = 0
    best_val = sum(P[:K])
    tmp = best_val
    for i in range(1, N-K+1):
        prev = P[i-1]
        suc = P[i+K-1]
        tmp = tmp-prev+suc
        if best_val < tmp:
            best_val = tmp
            best = i

    print(pleaseAC(P[best:best+K]))



main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__=="__main__":
    n, k = map(int, input().split())
    p = [int(x) for x in input().split()] 

    e = []
    esum = 0.0
    for i in range(k):
        e1 = float(p[i]+1.0)/2.0
        e.append(e1)
        esum += e1

    esum_prev = esum
    esum_max = esum

    for i in range(k,n):
        e1 = float(p[i]+1.0)/2.0
        e.append(e1)
        esum = esum_prev - e[i-k] + e1
        esum_max = max(esum_max, esum)
        esum_prev = esum  

    print(esum_max)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_lis = list(map(int, input().split()))
def calc_ex(num):
    return (num - 1) * 0.5 + 1
cur_num = 0
for i in range(k):
    cur_num += p_lis[i]
max_nums = cur_num
max_nums_i = 0
for i in range(len(p_lis) - k):
    cur_num -= p_lis[i]
    cur_num += p_lis[i + k]
    if max_nums < cur_num:
        max_nums = cur_num
        max_nums_i = i + 1
res = 0
for i in range(max_nums_i, max_nums_i + k):
    res += calc_ex(p_lis[i])
print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
res = [0]
ra = res.append
for i in range(n):
    ra(p[i] + res[i])

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

print((ans + k) / 2)

Submission status: Accepted

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

E = [0]
tmp = 0
for i in range(1, max(P) + 1):
    s = tmp + i
    E.append(s / i)
    tmp = s

PE = []
for p in P:
    PE.append(E[p])

m = 0
tmp = 0
for i in range(K-1, N):
    if i == K-1:
        s = sum(PE[0:i+1])
        m = s
        tmp = s
    else:
        s = tmp - PE[i - K] + PE[i]
        m = max(m, s)
        tmp = s

print(m)

Submission status: Accepted

Solution code:
from decimal import *
n, k = map(int, input().split())
p = list(map(int, input().split()))
ho_list = [0] * n

for j in range(0, n):
    ho_list[j] = (p[j] + 1) / 2

sum_list = [0] * (n + 1)
sum_list[0] = ho_list[0]
for i in range(1, n):
    sum_list[i] = sum_list[i - 1] + ho_list[i]
ans = 0

for i in range(k - 1, n):
    ans = max(ans, abs(sum_list[i] - sum_list[i - k]))
print("{:.12f}".format(ans))

Submission status: Accepted

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

for i in range(len(P_list)):
    P_list[i] = int(P_list[i]) / 2 + 0.5

tmp = sum(P_list[0:K])
ans = sum(P_list[0:K])

for j in range(len(P_list) - K):
    ans = max(ans, tmp - P_list[j] + P_list[j + K])
    tmp = tmp - P_list[j] + P_list[j + K]

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(n):
    if i <= k - 1:
        cnt += p[i]
        tmp = cnt
        end = i + 1
    else:
        cnt = cnt - p[i - k] + p[i]
        if cnt >= tmp:
            tmp = cnt
            end = i + 1

ans = 0
L = p[end - k: end]
for i in L:
    ans += sum(range(1, i + 1)) / i

print(ans)

Submission status: Accepted

Solution code:

import sys
import numpy as np
from collections import deque
from itertools import combinations
sys.setrecursionlimit(10**9)



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

    sum_0 = 0
    for i in range(K):
        sum_0 += p[i]


    sum_n = sum_0
    max = sum_0
    for i in range(N-K): # i+1
        sum_n = sum_n + p[i+K] - p[i]
        if max < sum_n:
            max = sum_n

    ans = (K + max) / 2
    print("{0:.6f}".format(ans))

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
from collections import deque

N,K = list(map(int,input().split(' ')))
P = list(map(int,input().split(' ')))
sigma_max = 0
sigma = 0

queue = deque()

count = 1
for p in P:
    if count<=K:
        queue.append(p)
        sigma += p
        if sigma>sigma_max:
            sigma_max=sigma
    else:
        d = queue.popleft()
        queue.append(p)
        sigma -= d
        sigma += p
        if sigma>sigma_max:
            sigma_max=sigma
    count+=1

print((sigma_max+K)/2.0)

Submission status: Accepted

Solution code:
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    ave=[(p+1)/2 for p in P]
    s=sum(ave[:k])
    ans=s
    for left in range(n-k):
        s -= ave[left]
        s += ave[left+k]
        if s>ans:
            ans = s
    print(ans)
main()

Submission status: Accepted

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

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

ans = []

if n == 1:
    print((p[0]+1)/2)
elif n == k:
    print((sum(p)+n)/2)
else:    
    for i in range(n-k):
        ans.append(P[i+k]-P[i])
    print((max(ans)+k)/2)

Submission status: Accepted

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

num_sum = 0

max_pair = (0, k-1)
for i in range(k):
    num_sum += p[i]
max_sum = num_sum

for i in range(k, len(p)):
    num_sum -= p[i-k]
    num_sum += p[i]
    # print(num_sum, i-k+1,i)
    if num_sum > max_sum:
        max_sum = num_sum
        max_pair = (i-k+1, i)
avg = 0
for i in range(max_pair[0], max_pair[1]+1):
    num = p[i]
    num_sum = round(num *(num+1)/(2*num), 10)
    avg += num_sum
print(avg)

Submission status: Accepted

Solution code:
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)

def main():
    n,k = map(int,input().split())
    p = list(map(int,input().split()))
    x = [0]
    _sum = 0
    for i in range(1,max(p)+1):
        _sum += i
        x.append(_sum)
    v = []
    ans = 0
    res = 0
    for i in range(n):
        v.append(x[p[i]]/p[i])
        if i >= k:
            res += v[i] - v[i-k]
        else:
            res += v[i]
        ans = max(ans,res)
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

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


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    
    pi_table = [0] + [(i * (i + 1) // 2) / i for i in range(1,1001)]
    
    pe = [None] * N
    for i in range(N):
        pe[i] = pi_table[p[i]]
    
    tmp = sum(pe[:K])
    ans = tmp
    for i in range(K, N):
        tmp += (pe[i] - pe[i - K])
        ans = max(ans, tmp)
        
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
nlist = list(map(int, input().split()))
Ktot = sum(i for i in nlist[:K])
maximum = Ktot
for l in range(N-K):
  Ktot = Ktot - nlist[l] + nlist[l+K]
  maximum = max(maximum, Ktot)
print((maximum+K)/2)

Submission status: Accepted

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

max_sum = sum(ps[:K])
num = sum(ps[:K])

for i in range(N-K):
    num = num - ps[i] + ps[i+K]
    max_sum = max(max_sum,num)
    

print((max_sum+K)/2)

Submission status: Accepted

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

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

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

mx = (0, 0)
for i in range(n-k+1):
    idx = i+k-1
    mx = max(mx, (cum[i+k]-cum[i], idx))

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

Submission status: Accepted

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

temp = 0 # MAX_K
for i in range(K):
  temp += p_list[i]
  
ans = temp
for i in range(K,N):
  temp = temp - p_list[i-K] + p_list[i]
  if ans < temp:
    ans = temp

print( (ans + K) /2 )

Submission status: Accepted

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

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

Ex = []
for m in range(n):
    Ex.append(Ex_dice(p[m]))
    
s = [0]*(n+1)
for j in range(n):
    s[j+1] = s[j] + Ex[j]
    
res = -100000
for i in range(n-k+1):
    val = s[k+i] - s[i]
    if res < val:
        res = val
print(res)

Submission status: Accepted

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

pi = [0.5*i + 0.5 for i in range(1001)]
H = [pi[p[i]] for i in range(N)]
sum_list = [0 for i in range(N-K)]
added = sum(H[0:K])
max_added = added
for k in range(K,N):
    added = added + H[k] - H[k-K]
    if added > max_added:
        max_added = added

print(max_added)