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()))

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

ans=s

for i in range(n-k):

    s += (p[i+k]-p[i])/2

    if s>ans:
        ans=s
print(ans)

Submission status: Accepted

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

def calc(x):
    return (x + 1) / 2


w = 0

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    # d = deque([0])
    d = [0]
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        sum_d = d[i + k] - d[i]
        if max_sum < sum_d:
            max_sum = sum_d
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum + k) / 2)

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    d = deque([0])
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        sum_d = d[i + k] - d[i]
        if max_sum < sum_d:
            max_sum = sum_d
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum + k) / 2)

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    d = deque([0])
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        sum_d = d[i + k] - d[i]
        if max_sum < sum_d:
            max_sum = sum_d
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum / 2) + (k * 0.5))

Submission status: Accepted

Solution code:
from collections import deque

if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    d = deque([0])
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        max_sum = max(max_sum, d[i + k] - d[i])
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum / 2) + (k * 0.5))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))
LL = []
for i in range(n):
    kitai = L[i]*(L[i]+1)//2/L[i]
    LL.append(kitai)
#print(LL)
k_sum = sum(LL[:k])
num = []
num.append(k_sum)
for i in range(1,n-k+1):
    k_sum += (LL[k+i-1] - LL[i-1])
    #print(LL[k+i-1],LL[i-1])
    num.append(k_sum)
print(max(num))

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    p1 = list(map(lambda x: (x+1)/2, p))
    ans = 0
    if k==1:
        print(max(p1))
        exit()
    else:
        initial = sum(p1[0:k])
        if ans <= initial:
            ans = initial
            cal = initial
        for i in range(n-k):
            cal = cal-p1[i]+p1[i+k]
            if ans <= cal:
                ans = cal
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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


def calc(value):
    return value * (value + 1) / (2 * value)


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

cur = max_value
for l in range(k, n):
    cur += (calc(p[l]) - calc(p[l-k]))
    max_value = max(max_value, cur)
print(max_value)

Submission status: Accepted

Solution code:
import numpy as np

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

# N, K = 10, 4
# P = [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]

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

cum_exp = np.cumsum(exp)

max = cum_exp[K-1]
for i in list(range(K, N)):
    val = cum_exp[i] - cum_exp[i - K]
    if val > max:
        max = val

print(max)

Submission status: Accepted

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

for key, v in enumerate(p):
    t = (v+1)*v//2/v
    s.append(s[key] + t)

ans = -1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy

n,k = map(int,input().split())
li = [(int(x)*(int(x)+1))/(2*int(x)) for x in input().split()]
a = numpy.cumsum(li)
ans = 0
for i in range(n-k+1):
    if i == 0:
        ans = a[i+k-1]
    else:
        if ans < (a[i+k-1] - a[i-1]):
            ans = a[i+k-1] - a[i-1]
print(ans)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    plist = list(map(int,input().split()))
    summax = sum(plist[:k])
    temp = summax
    for i in range(1,n-k+1):
        temp = temp + plist[i+k-1] - plist[i-1]
        if temp > summax:
            summax = temp
    print((summax+k)/2)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

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

data = []
input_data = input().split()
data = [int(n) for n in input_data]

data_exp = [0]
for i in range(n):
    data_exp.append(data_exp[i] + 1 + (data[i]-1)/2)

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

iter_num = n - k + 1

num = sum(p[0:k])
ans = [(num+k)/2]
for i in range(iter_num-1):
	num = num - p[i] + p[k+i]
	ans.append((num+k)/2)

print(max(ans))

Submission status: Accepted

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

summax=sum(plist[:k])


for i in range(n-k+1):
	if i == 0:
		temp=summax
	else:
		temp=temp+plist[i+k-1]-plist[i-1]
		if temp>summax:
			summax=temp

print((summax+k)/2)

Submission status: Accepted

Solution code:
def main():
    n , k = map(int, input().split())
    p = list(map(int, input().split()))
    size = max(p)
    sheet = [0]*size
    for i in range(size):
        if (i == 0):
            sheet[i]=1
        else:
            sheet[i] = (sheet[i-1]*i + (i+1))/(i+1)
    ans = 0
    total = 0
    for i in range(n-k+1):
        if (i == 0):
            for j in range(k):
                total += sheet[p[i+j]-1]
            if (total > ans):
                ans = total
        else:
            total -= sheet[p[i-1]-1]
            total += sheet[p[i+k-1]-1]
            if (total > ans):
                ans = total
    print (ans)
main()

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
max = 0
arr = list(map(int, input().split()))
cumsum = [0] * (a + 1)
for i in range(a):
  cumsum[i+1] = cumsum[i] + arr[i]
for i in range(a - b + 1):
  sum = 0
  sum = cumsum[i + b] - cumsum[i]
  if sum > max:
    max = sum
print((max + b) / 2)

Submission status: Accepted

Solution code:
#n=int(input())
n,k=map(int,input().split())
pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

expl=[0.0]
ansl=[]
cum=0
for i in range(n):
    cum+=(1+pl[i])/2
    expl.append(cum)

for i in range(n-k+1):
    ansl.append(expl[i+k]-expl[i])

print('{:.9f}'.format(max(ansl)))

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
p = list(map(int,input().split()))
S = [0]
a = 0
sum1 = 0
sumMax = 0
for i in range(N):
    a += p[i]
    S.append(a)
for i in range(N-K+1):
    sum1 = S[i+K] - S[i]
    if(sumMax < sum1):
        sumMax = sum1
result = 0.5*K + 0.5*(sumMax)
print(result)

Submission status: Accepted

Solution code:
from sys import stdin

n, k = (int(x) for x in stdin.readline().rstrip().split())
p = [int(x) for x in stdin.readline().rstrip().split()]
ev = [(i+1)/2 for i in p]
s = [ev[0]]
for i in range(1, n):
    s.append(s[i-1] + ev[i])

m = s[k-1]
for j in range(n-k):
    a = s[j+k] - s[j]
    if m < a:
        m = a

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

ruisekiwa =[0]
for x in P:
    ruisekiwa.append(ruisekiwa[-1]+x)
maxN =0
maxArg =[0]*2
maxArg[0] = 0
maxArg[1] = 0+K
for x in range(N-(K-1)):
    cal = ruisekiwa[x+K]-ruisekiwa[x]
    if maxN <cal:
        maxN = cal
        maxArg[0]=x
        maxArg[1]=x+K
kitai = 0
p = maxArg[1]-maxArg[0]
for y in range(maxArg[0],maxArg[1]):
    kitai +=  (P[y]+1)/2
    
    
print(kitai)

Submission status: Accepted

Solution code:
expected_value_dic = {}

def get_expected_value(x):
    return (1 + x) / 2

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

P = list(map(int, input().split()))
expected_values = [get_expected_value(p) for p in P]
cumulative_values = [expected_values[0]]
for expected_value in expected_values[1:]:
    cumulative_values.append(cumulative_values[-1] + expected_value)

result = cumulative_values[k-1]
for i in range(k, n):
    temp = cumulative_values[i] - cumulative_values[i - k]
    if temp > result:
        result = temp

print(result)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[0]*(N+1)
Kmax=-1
for i in range(N):
    Q[i+1]+=P[i]+Q[i]

for j in range(N-K+1):
    if Q[j+K]-Q[j]>Kmax:
        Kmax=Q[j+K]-Q[j]
print((Kmax+K)/2)

Submission status: Accepted

Solution code:
n,k = (int(x) for x in input().split())
list = [int(i) for i in input().split()]
sumlist = []
sum = 0;ans = 0
for l in range(n):
    list[l] = (1+list[l])/2

for i in range(n):
    sum += list[i]
    sumlist.append(sum)

if k!=n:
    for j in range(n-k):
        ans = max(ans,sumlist[j+k]-sumlist[j])
    print(ans)
else:
    print(sum)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
e=[]
for pp in p:
    ex=(pp+1)/2
    e.append(ex)
ans=0
for i in range(n-k+1):
    if i==0:
        t=sum(e[:k])
        ans+=t
        continue
    t-=e[i-1]
    t+=e[i+k-1]
    ans=max(ans,t)

print(ans)

Submission status: Accepted

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

st = 0
i = 0
sa = 0
while i+K < N:
    sa += p[i+K]-p[i]
    if sa > 0:
        st = i+1
        sa = 0
    i += 1

psum = p[st:st+K]
for i in range(K):
    psum[i] = (psum[i]+1)/2
print(sum(psum))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int,input().split()))
E = []
for i in range(N):
    E.append((p[i]+1)/2)
S = [0]
num = 0
for i in range(N):
    num += E[i]
    S.append(num)
Max = 0
for i in range(N-K+1):
    Max = max(Max, S[K+i]-S[i])
print(Max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = map(int,input().split())
    li = list(map(int,input().split()))
    pi_list = [(i + 1) / 2 for i in li]
    spot = 0
    for i in range(k):
        spot += pi_list[i]
    ans_li = []
    ans_li.append(spot) 
    for i in range(n-k):
        spot -= pi_list[i]
        spot += pi_list[i+k]
        ans_li.append(spot)
    print(max(ans_li))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
p = list(map(int,input().split()))
summ = sum(p[i] for i in range(K))
sum_list = [summ]
maximum = 0

for i in range(N - K):
    summ += p[i + K] - p[i]
    sum_list.append(summ)

maximum = max(sum_list)

print("{}".format((maximum + K) / 2))

Submission status: Accepted

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

print('{:.8f}'.format(max))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n, k = (int(x) for x in input().split())
p = np.array(list(int(x) for x in input().split()))

p = (p + 1) / 2

sump = []
e = []
s = 0

for i in range(len(p)):
    s += p[i]
    sump.append(s)

sump.insert(0, 0)
sump = np.array(sump)

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


print(max(e))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
num=list(map(float,input().split()))
a=0
check=0
for i in range(N):
    num[i]=(num[i]+1)/2
    if i<K:
        check+=num[i]
a=check        
for i in range(N-K):
    ans=check-num[i]+num[K+i]
    if ans>a:
        a=ans
    check=ans  
print(a)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
pList = list(map(int, input().split()))
pKList = [(1 + p)/2 for p in pList]
pListMax = 0

for i in range(n-k+1):
    if i == 0:
        res = sum(pKList[i:i+k])
    else:
        res = res - pKList[i-1] + pKList[i+k-1]
    pListMax = max(pListMax, res)
print(pListMax)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
    P[i]=0.5*(P[i]+1)
x=sum(P[:k])
s=[x]

for i in range(1,n-k+1):
    x=x-P[i-1]+P[i+k-1]
    s.append(x)

print(max(s))

Submission status: Accepted

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

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

t = sum(m[0:k])
result = t
for i in range(n-k):
   t -= m[i]
   t += m[i+k]
   if t > result:
      result = t

print(result)

Submission status: Accepted

Solution code:
nk = [int(s) for s in input().split()]
n = nk[0]
k = nk[1]

p = [int(s)+1 for s in input().split()]
l = [sum(p[:k])]

for x in range(n-k):
  l.append(l[x]-p[x]+p[x+k])
print(max(l)/2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
q=[(1+pp)/2 for pp in p]
ans=0
c=[0]
for qq in q:
      c.append(c[-1]+qq)
ans=0

for qq in range(k,1+n):
  ans=max(ans,c[qq]-c[qq-k])

print(ans)

Submission status: Accepted

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

sum_max = 0
for i in range(k - 1, n):
    if i == k - 1:
        sum_now = sum(ps[:i + 1])
    else:
        sum_now = sum_now + ps[i] - ps[i - k]
    sum_max = max(sum_max, sum_now)
    
print(float(sum_max + k) / 2)

Submission status: Accepted

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

Submission status: Accepted

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

# expectancy 1 + 2 + ... + p / p = p * (p + 1) / p / 2 = (p + 1) / 2

sum_max = 0
for i in range(k - 1, n):
    if i == k - 1:
        sum_now = sum(ps[:i + 1])
    else:
        sum_now = sum_now + ps[i] - ps[i - k]
    sum_max = max(sum_max, sum_now)

print((sum_max + k) / 2)

Submission status: Accepted

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

p_sum = 0
ans = 0
for i in range(n):
    p_sum += p[i]
    if i >= k:
        p_sum -= p[i - k]

    ans = max(p_sum, ans)

ans = (ans + k) / 2

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[(int(i)+1)/2 for i in input().split()]
summ=sum(a[:k]) 
maxx=summ
for i in range(len(a)-k):
    summ-=a[i]
    summ+=a[i+k]
    maxx=max(maxx,summ)
print(maxx)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

temp = 0
S = [0]

for i in range(N):
    S.append(S[-1] + kitai(p[i]))
    
    
temp = 0

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

Submission status: Accepted

Solution code:
def dice_in_line(k, p_list):
    max_line = [0 for i in range(k+1)]
    max_sum = 0
    sum_list = [0]
    for i in range(len(p_list)):
        sum_list.append(p_list[i]+sum_list[i])
    for i in range(len(p_list)-k+1):
        if max_sum < sum_list[i+k]-sum_list[i]:
            max_sum = sum_list[i+k]-sum_list[i]
        
    return (max_sum+k)/2.0

n, k = [int(i) for i in input().split()]
p_list = [int(p) for p in input().split()]

print(float(dice_in_line(k, p_list)))

Submission status: Accepted

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

V = []
for i, p in enumerate(P):
    V.append((p + 1) / 2)

psum = sum(V[:K])
ans = psum
for i in range(K, len(V)):
    psum -= V[i - K]
    psum += V[i]
    ans = max(ans, psum)
print(ans)

Submission status: Accepted

Solution code:
#D
N, K = map(int, input().split())
p= [int(x) for x in input().split()]
ap = p
ans = 0
for i in range(N):
    if i == 0:
        ap[i] = (p[i]+1)/2
    else:
        ap[i] = (p[i]+1)/2 + ap[i-1]
for i in range(N-K+1):
    now = 0
    if i == 0:
        now = ap[K-1]
    else:
        now = ap[K+i-1]-ap[i-1]
    ans = max(ans, now)

print (ans)

Submission status: Accepted

Solution code:
N, K=map(int,input().split())
P=list(map(int,input().split()))
Sum=[0]* (N + 1)
for i in range(N):
    Sum[i+1]=Sum[i]+(P[i]+1)/2.0
Ans=0
for i in range(N-K+1):
    Ans=max(Ans,Sum[i+K]-Sum[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

sum_list = [0] * N

for i in range(N):
    if i == 0:
        sum_list[i] = p[i]
    else:
        sum_list[i] = sum_list[i-1]+p[i]
res = sum_list[K-1]

for i in range(N):
    if i < K:
        continue
    if sum_list[i] - sum_list[i-K] > res:
        res = sum_list[i] - sum_list[i-K]

print(res)

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
dices = map(int, input().split())
dices_EV = list(map(lambda x:(x+1)/2, dices))
dices_EV_accumulate = list(itertools.accumulate(dices_EV))
dices_EV_sums = [dices_EV_accumulate[i+k] - dices_EV_accumulate[i] for i in range(n-k)]
dices_EV_sums.append(dices_EV_accumulate[k-1])
print(max(dices_EV_sums))

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
s = 0
for i in range(k):
    s = s + p[i]
mx = s
for i in range(k, n):
    s += p[i] - p[i - k]
    mx = max(mx, s)
print(mx)

Submission status: Accepted

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

dp = [0] * (n + 1)

for i in range(n):
    dp[i+1] = dp[i] + (pl[i] + 1)/2

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s, t  = map(int, input().split())
u = list(map(int,input().split()))
ln = []
for i in u:
    ln.append((1 + i)/2)

from itertools import accumulate

B = [0] + ln

B = list(accumulate(B)) 
answer = []

for i in range(s-(t-1)):
    answer.append(B[i+t]-B[i])

print(max(answer))

Submission status: Accepted

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

def expected(x):
    return (x+1)/2

def test3():
    e_n = list(map(expected, p_n))
    s_n = []
    for i, e in enumerate(e_n):
        if i == 0:
            s_n.append(e)
            continue
        s_n.append(s_n[i-1] + e)
    result = []
    result.append(s_n[k-1])
    for i in range(len(s_n)):
        if i+k >= n:
            continue
        result.append(s_n[i+k]-s_n[i])
    print(max(result))      
test3()

Submission status: Accepted

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

max_value = sum((p_i + 1) / 2 for p_i in p[:k])
cur = max_value
for i in range(k, n):
    cur += ((p[i] + 1) / 2 - (p[i-k] + 1) / 2)
    max_value = max(max_value, cur)
print(max_value)

Submission status: Accepted

Solution code:
import numpy as np

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    # list of expected value
    e = [(p[j-1]+1)/2.for j in range(1, n+1)]
    # cumulative sum for e
    c_s = np.cumsum(e)
    # sum of range k
    s = c_s[k-1:] - np.r_[[0],c_s[:n-k]]
    # calculate max of s
    ans = max(s)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

def kitaiti(num):
    result = (num+1)*num/(num*2)
    return result
r = [kitaiti(p[i]) for i in range(n)]

result = [sum(r[:k])]
for i in range(k, n):
    result.append(result[-1]-r[i-k]+r[i])
print(max(result))

Submission status: Accepted

Solution code:

import numpy as np
from collections import deque

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

p = (1.+p)/2.
q = deque()

ans = 0.
tmp = 0.
for i in range(len(p)) : 
    q.append(p[i])
    tmp += p[i]
    if ( len(q) == K ) : 
        ans = max(ans, tmp)
        tmp -= q.popleft()

print("{:.10f}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

m = max(p)
l = [0]
for i in range(1,m + 1):
    l.append(l[-1] + i)
for i in range(1,len(l)):
    l[i]/=i
for i in range(n):
    p[i] = l[p[i]]

#累積和
for i in range(1,len(p)):
    p[i]+=p[i - 1]
p=[0]+p

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
 
exp = []
sum_list = []
result_list = []
result = 0
count = 0
tmp = 0
for i in range(N):
    if count < K-1:
        a = (p[i]+1)/2
        exp.append(a)
        tmp += a
    else:
        a = (p[i]+1)/2
        exp.append(a)
        tmp += a
        sum_list.append(tmp)
        tmp -= exp[count-K+1]
    count += 1

print(max(sum_list))

Submission status: Accepted

Solution code:
from decimal import*
from fractions import*
import math
import functools


import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines 

def cmp(a,b):
    if(a<b):
        return 1
    elif(a==b):
        return 0
    else:
        return -1 

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

lit=[]
for num in p:
    Sum=num*(num+1)/2
    lit.append(Sum/num)
Sum=0
ans=0
for i in range(k):
    Sum+=lit[i]
ans=Sum
for i in range(k,n):
    Sum-=lit[i-k]
    Sum+=lit[i]
    ans=max(ans,Sum)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines  

from itertools import accumulate

N, K = map(int, input().split())
P = list(map(int, input().split()))
Pcum = list(accumulate([0] + [(1+p)/2 for p in P]))

ans = max(right - left for left, right in zip(Pcum, Pcum[K:]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
for i in range(K):
    s += p[i]
ans = (K+s)/2

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, K = map(int, input().split())
p = [int(i) for i in input().split()]
p = np.array(p)
p = (p + 1)/2
p = np.cumsum(np.insert(p, 0, 0))
stride = K
print(np.max(p[stride:] - p[:-stride]))

Submission status: Accepted

Solution code:
def exp(x):
  return (1+x) / 2

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

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

print(max)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
E = [p*(p+1)//2/p for p in P]
cE = [E[0]]
for i in range(1,N): cE.append(cE[-1]+E[i])
cE = [0]+cE
sE = []
i = 0
while i+K < len(cE):
    sE.append(cE[i+K]-cE[i])
    i += 1
print(max(sE))