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

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

for k in range(N-K+1):
    if k > 0:
        q = q - P[k-1] + P[K-1+k]
    if m < q:
        m = q

print((m+K)/2)

Submission status: Accepted

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

e_table = [0]
pre = 0
for i in range(1,1001):
    e_table.append((pre + i)/i)
    pre = pre + i

lis = [0] * K
SUM = 0
maximam = 0

for i, p in enumerate(input().split()):
    p = int(p)
    lis.append(e_table[p])
    SUM = SUM - lis[i] + lis[-1]
    maximam = max(maximam, SUM)
print(maximam)

Submission status: Accepted

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

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

edge=A[0]
s=sum(A[:K])
max_s=s
for i in range(1,N-K+1):
  s=s-edge+A[i+K-1]
  max_s=max(max_s,s)
  edge=A[i]
print(max_s)

Submission status: Accepted

Solution code:
import sys


TEST_INPUT = [
    """
    5 3
    1 2 2 4 5
    """,
    """
    4 1
    6 6 6 6
    """,
    """
    10 4
    17 13 13 12 15 20 10 13 17 11
    """
]
ANSWER = [
    "7.0",
    "3.5",
    "32.0"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, k, p_list):
    res = sum(p_list[:k])
    res_temp = res
    for i in range(n - k):
        res_temp -= p_list[i]
        res_temp += p_list[i + k]
        if res_temp > res:
            res = res_temp
    return (res + k) / 2


def input_and_solve(ih):
    n, k = map(int, ih.input().split())
    p_list = list(map(int, ih.input().split()))
    res = solve(n, k, p_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert abs(float(res) - float(ans)) < 0.00000001


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

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

ls = list(map(int,input().split()))
ls = [(x+1)/2 for x in ls]

m = tot = sum(ls[:k])
for i in range(1,n-k+1):
  tot = tot-ls[i-1]+ls[i+k-1]
  m = max(m, tot)
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

M = [(1+p)/2 for p in P]
result = [0, ]

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

print(sum(M[:K]) + max(result))

Submission status: Accepted

Solution code:
import numpy as np

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


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

p_arr = np.array(p_list)

p_mean = (p_arr + 1) / 2


sum_move = p_mean[:K].sum()


ans = sum_move

for i in range(N-K):
    sum_move = sum_move - p_mean[i] + p_mean[i+K]
    if ans < sum_move:
        ans = sum_move

print(ans)

Submission status: Accepted

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

def calc_e(v):
    if v % 2 == 0:
        return v // 2 + 0.5
    return v // 2 + 1

sum_max = 0
tmp = 0
max_i = 0
for i in range(N):
    sum_max += p[i]
    if i >= K - 1:
        # 合計値の最大値を出す
        if tmp < sum_max:
            # iを管理
            max_i = i
            tmp = sum_max
        sum_max -= p[i-(K-1)]

ret = 0
for i in range(max_i-K+1,max_i+1):
    ret += calc_e(p[i])
print(ret)

Submission status: Accepted

Solution code:
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N
#math.ceilで切り上げ
import math
import string

def intinput():
    return int(input())

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

def splitintinput():
    return map(int,input().split())

N, K = splitintinput()
p = listintinput()
tmpsum = 0
maxsum = 0
tmp = 0
for i in range(K):
    tmpsum += p[i]
maxsum = tmpsum
for i in range(K,N):
    tmpsum = tmpsum - p[i-K] + p[i]
    if tmpsum > maxsum:
        tmp = i
        maxsum = tmpsum

print((maxsum+K)/2)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = [(1+x)/2 for x in p]
s = 0
start = 0
end = k-1
s = sum(p[start:end+1])
res = s
while end+1<n:
    s -= p[start]
    start+=1
    end+=1
    s += p[end]
    res = max(s,res)

print(res)

Submission status: Accepted

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

cumsum = [0]
for n in range(1, N+1):
  cumsum.append(cumsum[n-1] + (pn[n-1] + 1)/2)

max_exp = 0
for n in range(K, N + 1):
  max_exp = max(max_exp, cumsum[n] - cumsum[n-K])
print(max_exp)

Submission status: Accepted

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

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

aaaa=(ans+k)/2
print(aaaa)

Submission status: Accepted

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

sum_acc = []
tmp = 0
for i in range(N):
  tmp += (P[i]+1)/2
  sum_acc.append(tmp)
  
#print(sum_acc)
sum_max = 0  
for i in range(N):
  if(i == K-1):
   sum_tmp = sum_acc[i]
   sum_max = max(sum_tmp,sum_max)
  elif(i >= K): 
   sum_tmp = sum_acc[i]-sum_acc[i-K]
   sum_max = max(sum_tmp,sum_max)

print(sum_max)

Submission status: Accepted

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

s = sum(p[:k])
left = p[0]
m = s
for i in range(n - k):
    s = s - p[i] + p[i + k]
    m = max(m, s)

ans = (k + m) / 2
print(ans)

Submission status: Accepted

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

for j in range(X-1):
    Y[j+1] = Y[j]-(p[j]+1)/2+(p[j+K]+1)/2

print(max(Y))

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
x = 0
for i in range(k):
    x += p[i]
saidai = x
for i in range(n-k):
    x -= p[i]
    x += p[i+k]
    if x > saidai:
        saidai = x
print(saidai)

Submission status: Accepted

Solution code:
inputf = input

N, K = [int(x) for x in inputf().split(" ")]
P = [int(x) for x in inputf().split(" ")]
exp = [ (p*(p+1)//2)/p for p in P]
res = []
res.append(sum(exp[:K]))
for i in range(N-K):
    res.append(res[i]-exp[i]+exp[i+K])
print(max(res))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
m=-1
s=0
s+=sum(p[0:k])
for i in range(len(p)-k):
    s+=p[i+k]
    s-=p[i]
    if m < s:
        m=s
print((m+k)/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]=0.5*(p[i]+1)

_sum=sum(p[:k])
_max=sum(p[:k])

for g in range(k,n):
    _sum=_sum+p[g]-p[g-k]
    _max = max(_sum,_max)
print(_max)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
L = list(map(lambda x: (int(x) + 1) / 2, input().split()))

previous = sum(L[:k])
current_max = previous
for i in range(n-k):
    # print(previous)
    after = previous - L[i] + L[i+k]
    current_max = max(current_max, after)
    previous = after

print(current_max)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
for i in range(N):
    l = p[i]
    p[i] = ((1+p[i]) * p[i])//2
    p[i] = p[i]/l
ans = 0
for i in range(K):
    ans +=p[i]
l = ans
for i in range(K,N):
    ans = ans + p[i] - p[i-K]
    l = max(l,ans)
print('{:.8f}'. format(l))

Submission status: Accepted

Solution code:
from itertools import accumulate
def main():
    n,k=map(int,input().split())
    P=list(map(int,input().split()))
    E=[0]*n
    for i,p in enumerate(P):
        E[i]=(1+p)/2
    Acc=[0]+list(accumulate(E))
    ans=0
    for i in range(n-k+1):
        ans=max(ans,Acc[i+k]-Acc[i])
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    p = [int(s) for s in sys.stdin.readline().strip().split()]

    pd = [0.0] * n
    for i in range(n):
        tot = (p[i] + 1) * p[i] // 2
        ex = tot / p[i]
        pd[i] = ex

    cand = sum(pd[:k])
    ans = cand
    for i in range(k, n):
        cand += pd[i]
        cand -= pd[i-k]
        ans = max(ans, cand)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

possibility=list(map(lambda x:(1+x)/2,p_l))


max_p=sum(possibility[0:k:1])
tmp=max_p
for i in range(1,len(possibility)-k+1):
    tmp+=possibility[i+k-1]-possibility[i-1]
    if tmp>max_p:
        max_p=tmp
        
print(max_p)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
e = list(map(lambda x: (int(x)+1)/2, input().split()))

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

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

Submission status: Accepted

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

Submission status: Accepted

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, K = read_ints()
P = read_ints()


def ret_mean(X):
    return (X + 1) / 2


P_mean = [ret_mean(p) for p in P]

from itertools import accumulate
P_accum = [0] + list(accumulate(P_mean))

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = [(int(x)+1)/2 for x in input().split()]
cm = [0]
for n in p:
    cm.append(cm[-1]+n)
ans = 0
for n in range(N-K+1):
    ans = max(cm[n+K]-cm[n],ans)
print(ans)

Submission status: Accepted

Solution code:
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(3, [1, 2, 2, 4, 5]), 7.0)

    def test_2(self):
        self.assertEqual(think(1, [6, 6, 6, 6]), 3.5)

    def test_3(self):
        self.assertEqual(think(4, [17, 13, 13, 12, 15, 20, 10, 13, 17, 11]), 32.0)


def solve():
    k, p = read()
    result = think(k, p)
    write(result)


def read():
    n, k = read_int(2)
    return k, read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, p):
    prob = [0 for _ in range(len(p))]
    for i, elem in enumerate(p):
        prob[i] = (elem * (elem + 1)) / (2 * elem)
    prob = [0.0] + prob
    accumulated = [0.0 for _ in range(len(prob))]
    for i in range(len(prob)):
        if i == 0:
            continue
        accumulated[i] = accumulated[i - 1] + prob[i]

    maximum_expectation = -1
    for i in range(len(accumulated)):
        if i + k >= len(accumulated):
            break
        maximum_expectation = max(maximum_expectation, accumulated[i + k] - accumulated[i])
    return maximum_expectation


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
p = inl()
sm = sum(p[:k])
mx = sm
#ddprint(sm)
for i in range(1,n-k+1):
    sm += p[i+k-1]-p[i-1]
    #ddprint(sm)
    mx = max(mx,sm)
print((mx+k)/2)

Submission status: Accepted

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


N, K = map(int, input().split())
P = list(map(int, input().split()))
sumP = []
max_idx = None
max_val = -float('inf')
for i in range(N - K + 1):
    if i == 0:
        max_val = sum(P[i:i + K])
        max_idx = i
        prv_val = sum(P[i:i + K])
    else:
        if max_val < prv_val + P[i + K - 1] - P[i - 1]:
            max_val = prv_val + P[i + K - 1] - P[i - 1]
            max_idx = i
        prv_val = prv_val + P[i + K - 1] - P[i - 1]

ans = 0
for i in range(K):
    ans += calc_kitai(P[max_idx + i])
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
nk = input().split(" ")
n = int(nk[0])
k = int(nk[1])
p = input().split(" ")
for i in range(n):
    p[i] = int(p[i])

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

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

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

Submission status: Accepted

Solution code:
import sys
import itertools

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    ans = 0
    P2 = []
    for i in range(N):
        P2.append((P[i] / 2) * (P[i] + 1) / P[i])

    if N == 1:
        print(max(P2))
        return
    if N == K:
        print(sum(P2))
        return
    P3 = list(itertools.accumulate(P2))
    for i in range(N - K):
        ans = max(ans, P3[i + K] - P3[i])



    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

max = 0

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

print(max)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
n,k=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(n-k+1)
A=[0]*1100
sum_=0
for a in range(1,len(A)):
    sum_+=a
    A[a]=sum_/a
for a in range(k):
    S[0]+=A[P[a]]
for a in range(1,n-k+1):
    S[a]=S[a-1]
    S[a]+=A[P[k+a-1]]
    S[a]-=A[P[a-1]]
print(format(float(max(S)), '.20f'))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

total = [0] * 1001
total[0] = None
total[1] = 1.0
for i in range(2, 1001):
    total[i] = total[i-1] + 0.5
for i in range(N):
    p[i] = total[p[i]]
p = [0] + list(accumulate(p))

ans = 0
for i in range(0, N-K+1):
    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()))
max_p=max(p)
e=[-1 for _ in range(max_p+1)]


def calc_e(i):
    if(e[i]==-1):
        ei=(i+1)/2
        e[i]=ei
        return ei
    else:
        return e[i]

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

now_e=ans
for i in range(1,n-k+1):
    now_e-=calc_e(p[i-1])
    now_e+=calc_e(p[i+k-1])
    if(ans<now_e):
        ans=now_e
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
p = list(map(int, input().split()))
new_p=[]
for num in p:
    new_p.append((num+1)/2)

sm=0
for i in range(k):
    sm+=new_p[i]
mx=sm

for i in range(1,n-k+1):
    sm-= new_p[i-1]
    sm+= new_p[i+k-1]
    if mx < sm:
        mx=sm

print(mx)

Submission status: Accepted

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

B = [0]
for i in range(N):
    B.append(B[i] + P[i])

total = 0
start = 0
for i in range(K, N+1):
    if total < B[i] - B[i-K]:
        total = max(total, B[i] - B[i-K])
        start = i-K

table = [0]*1001
for i in range(1, 1001):
    for j in range(1, i+1):
        table[i] += j * (1 / i)

ans = 0
for i in range(start, start+K):
    ans += table[P[i]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n, k = map(int, input().split())
acc = list(itertools.accumulate(range(1001)))
p = list(map(int, input().split()))
for i in range(n):
    temp = p[i]
    p[i] = acc[p[i]]
    p[i] /= temp
ans = 0
p = [0] + p
acc_2 = list(itertools.accumulate(p))
for i in range(n-k+1):
    ans = max(ans, acc_2[i+k] - acc_2[i])
print(ans)

Submission status: Accepted

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

for i, p in enumerate(P):
  P[i] = (1 + p) / 2
  
sum_ = sum(P[:K])
res = sum_

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
ex = [(x + 1) / 2 for x in nums]

cur = sum(ex[:k])
ans = cur
for i in range(0, n - k):
	cur = cur + ex[i + k] - ex[i]
	ans = max(ans, cur)

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
rui = [0] * (N + 1)

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

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import *
n,k,*p=map(int,open(0).read().split())
a=[(1+i)/2 for i in p]
b=list(accumulate(a))
ans=0
if k==1:
    ans=max(a)
elif k==n:
    ans=b[-1]
else:
    for i in range(n-k):
        ans=max(ans,b[i+k]-b[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):
  if i!=0:
    P[i]=P[i-1]+(P[i]+1)/2
  else:
    P[i]=(P[i]+1)/2
    
ans=P[K-1]
for i in range(N-K+1):
  ans=max(ans,P[i+K-1]-P[i-1])
    
print(ans)

Submission status: Accepted

Solution code:
fact = [0]*1010
for i in range(1, 1010): fact[i] = fact[i-1]+i

n, k, *a = map(int, open(0).read().split())
a = list(map(lambda x:fact[x]/x, a))
ans = tmp = sum(a[:k])
for i in range(n-k):
    tmp -= a[i]
    tmp += a[i+k]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    vn = vk = vn_k = 1
    for i in range(1, n+1):
        vn = vn * i % modp
        if i == k:
            vk = vn
        if i == n-k:
            vn_k = vn
    return vn * get_inv(vk, modp) * get_inv(vn_k, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N, K = mis()
    A = lmis()
    tmp = sum(A[:K])
    tmp_max = tmp
    for i in range(K, N):
        tmp += A[i] - A[i-K]
        tmp_max = max(tmp_max, tmp)
    print((tmp_max+K)/2)


main()

Submission status: Accepted

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

pro = 0
for i in range(k):
    pro += arr[i]


ans = pro
for i in range(k,n):
    pro = pro + arr[i]-arr[i-k]
    if pro > ans:
        ans = pro

# print(ans)
print((ans+k)/2)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
n, k = [int(i) for i in sys.stdin.readline().split()]
p_ls = [int(i) for i in sys.stdin.readline().split()]
ls = []
for i, p in enumerate(p_ls, 1):
    ls.append((1 + p) / 2)
ans = 0
cur = 0
for i, l in enumerate(ls):
    if i >= k:
        cur -= ls[i-k]
    cur += l
    ans = max(ans, cur)
print(ans)

Submission status: Accepted

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

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

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

exp_val = sum(exp[:K])

max_ = exp_val
for i in range(K, N):
    exp_val += exp[i]
    exp_val -= exp[i - K]

    max_ = max(max_, exp_val)

print(max_)

Submission status: Accepted

Solution code:
n, k = map(int, input().split(" "))
ps = list(map(int, input().split(" ")))
k_sum = sum(ps[:k])
tmp_max = k_sum

for next_idx in range(k, n):
    rm = next_idx - k
    val_rm = ps[rm]
    val_add = ps[next_idx]
    k_sum = k_sum - val_rm + val_add
    tmp_max = max(tmp_max, k_sum)
print((tmp_max + k) / 2)

Submission status: Accepted

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

p = [(x+1)/2 for x in map(int, input().split())]

ans = sum(p[0:k])
prev = ans

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

print(ans)

Submission status: Accepted

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


ans = 0
now = 0
sum = 0
E = [0] * n

for i in range(n):
    E[i] = 0.5 + p[i]/2
    now += E[i]
    if(i == k-1):
        ans = now
    elif(i >= k):
        now -= E[i-k]
        ans = max(ans,now)

print(ans)

Submission status: Accepted

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

S = [0]*N

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = [0.0]
for i in range(N):
    ans.append(ans[-1]+A[i]/2.0+0.5)
ANS = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    n, k = get_list()
    li = get_list()
    ans = sum(li[:k])
    sm = ans
    for i in range(n-k+1):
        ans = max(ans, sm)
        if i<n-k:
            sm += li[i + k] - li[i]
    print((ans+k)/2)



''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p_list = list(map(lambda x: (int(x) + 1) / 2, input().split()))

sum_k = 0
for i in range(k):
    sum_k += p_list[i]
sum_max = sum_k
for i in range(k, n):
    sum_k -= p_list[i-k]
    sum_k += p_list[i]
    if(sum_k > sum_max):
        sum_max = sum_k
print(sum_max)

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

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

Submission status: Accepted

Solution code:

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


ans = 0
for i in range(K):
    ans += P[i]

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

print((max_ans + K)/2)

Submission status: Accepted

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

next_end = K

num = sum(P[:next_end])

max_num = num

for start in range(1, N - K + 1):
    num -= P[start - 1]
    num += P[next_end]
    max_num = max(num, max_num)
    next_end += 1

print((max_num + K) / 2)

Submission status: Accepted

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