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:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    1 2
    /2 = 1.5

    1 2 3 4
    /4 = 2.5

    1 2 3 4 5
    /5 = 3
    """
    N, K = read_ints()
    expectations = [(p+1)/2 for p in read_ints()]
    max_e = current = sum(expectations[:K])
    for i in range(1, N-K+1):
        # remove i-1 add i+K
        current = current-expectations[i-1]+expectations[i+K-1]
        max_e = max(max_e, current)
    return max_e


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
p = [(int(x)+1)/2 for x in stdin.readline().rstrip().split()]

m = sum(p[0:k])
maxm = m

for i in range(1,n-k+1):
    m = m - p[i-1] + p[i+k-1]
    maxm = max([maxm,m])

print(maxm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,k = I2()
    p = Intl()
    s = 0
    for i in range(k):
        s += (p[i] + 1)/2
    ans = s
    for i in range(k,n):
        s += (p[i] + 1)/2
        s -= (p[i-k] + 1)/2
        ans = max(ans,s)
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

n,k=map(int,input().split())
L=list(map(int,input().split()))
M=[(1+i)/2 for i in L]
N=[0]+list(accumulate(M))
ans = 0
for i in range(k,n+1):
    val = N[i]-N[i-k]
    ans = max(val,ans)
print("%.6f"%ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n, k = map(int, input().split())
P = list(map(int, input().split()))
P = list(map(lambda x: (x + 1) * x / 2 / x, P))
P = np.array([0] + P)
P = np.cumsum(P)
ans = np.zeros(n - (k - 1))
for i in range(n - (k - 1)):
    ans[i] = P[k + i] - P[i]
print(np.max(ans))

Submission status: Accepted

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

pp = list(map(lambda x:(x+1)/2,p))

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



walist=[p_rui[k-1]]
for i in range(0,n-k):
    walist += [p_rui[k+i]-p_rui[i]]

print(max(walist))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
s = [float()]
for i in range(n):
    s.append(s[i] + p[i])
print(max(s[i + k] - s[i] for i in range(n - k + 1)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
c = sum(p[:k])
ans = c
for i in range(n - k):
    c = c + p[i + k] - p[i]
    ans = max(c, ans)
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(lambda x: (x+1)/2, P))

Q_cum = list(accumulate([0] + Q))
res = 0
for i in range(N-K+1):
    temp = Q_cum[i+K]- Q_cum[i]
    res = max(res, temp)
print(res)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = list(map(int, input().split()))
prospect = []
for k in range(N):
  if p[k]%2 == 1:
    prospect.append((p[k]+1)>>1)
  else:
    prospect.append((p[k]+1)/2)
S = sum(prospect[:K])
ans = 0 + S
for k in range(N-K):
  S += prospect[k+K] - prospect[k]
  ans = max(ans, S)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


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

  PP = [0]*N
  for i, p in enumerate(P):
    PP[i] = p*(p+1)/(2*p)

  S = [0]*(N+1)
  for i in range(1, N+1):
    S[i] = PP[i-1] + S[i-1]

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

  print(max_)


if(__name__ == '__main__'):
  main()

Submission status: Accepted

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, k = MI()
    p = LI()
    max_seq = sum(p[:k])

    current = sum(p[:k])

    for i in range(k, n):
        current = current - p[i - k] + p[i]
        max_seq = max(max_seq, current)

    print((max_seq + k) / 2)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
p = l()
x = list(itertools.accumulate(p))

if n==1:
    print((p[0]+1)/2)
    sys.exit()

if n==k:
    print((x[-1]+k)/2)
    sys.exit()

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

print((ans+k)/2)

Submission status: Accepted

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

    E=[]

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

    S=[0]

    s=0
    for i in E:
        s+=i
        S.append(s)

    max=0
    right=0
    left=right+K

    while left<len(S):
        res=S[left]-S[right]
        if res>=max:
            max=res
        right+=1
        left=right+K

    print(max)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
list_P = list(map(int, input().split()))
cnt = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,K = LI()
p = LI()
E_half = np.array(p) + 1

def main():
    Pcum = np.zeros(N + 1, np.int32)
    Pcum[1:] = E_half.cumsum()
    # print(E_half)
    # print(Pcum)
    partial_sums_E_half = np.zeros(N-K+1, np.int32)
    for i in range(N-K+1):
        partial_sums_E_half[i] = Pcum[i+K] - Pcum[i]

    # partial_sums = Pcum[K:] - Pcum[0:-K]
    return (partial_sums_E_half.max())/2
print(main())

Submission status: Accepted

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

sum_k = sum( p[ : k ] )
max_sum_k = sum_k

for i in range( k, n ):
    sum_k += p[ i ] - p[ i - k ]
    if sum_k > max_sum_k:
        max_sum_k = sum_k

print( ( max_sum_k + k ) / 2 )

Submission status: Accepted

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

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

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

ans = 0
for i in range(n - k + 1):
    ans = max(ans, s[i + k] - s[i])
print('{:.12f}'.format(ans))

Submission status: Accepted

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

print((maxs+k)/2)

Submission status: Accepted

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

for i, j in enumerate(p):
    p[i] = (j*(j+1)/2) / j 
t_sum = sum(p[:k])
ans = t_sum
for i in range(n-k):
    t_sum = t_sum - p[i] + p[i+k]
    if ans < t_sum:
        ans = t_sum
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
c=list(map(int,input().split()))
a=[]
for x in range(n):
  s=c[x]
  t=(s+1)/2
  a.append(t)
  
ans=0
b=[]
b.append(a[0])

for y in range(n-1):
  c=b[y]
  d=b[y]+a[y+1]
  b.append(d)
  
dd=b[k-1]
for z in range(1,n+1-k):
  e=b[z+k-1]-b[z-1]
  
  dd=max(dd,e)

print(dd)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
E = list(map(lambda x: (float(x) + 1) / 2, input().split()))
res = sum(E[:K])
t = res
for i in range(K, N):
    t += -E[i - K] + E[i]
    res = max(res, t)
print(res)

Submission status: Accepted

Solution code:
from itertools import accumulate

N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) + 1, input().split()))
P_cumsum = [0] + list(accumulate(P))
print(max([P_cumsum[i+K]-P_cumsum[i] for i in range(N-K+1)])/2)

Submission status: Accepted

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

S=[0]*(N+1)
for i in range(1,N+1):
    S[i]=S[i-1]+P[i]

M=-1
for j in range(N-K+1):
    M=max(M,S[j+K]-S[j])
print((M+K)/2)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
q=[]
q.append(0)
for i in range(len(p)):
  q.append(q[-1]+p[i])
maxi=q[K]-q[0]
for i in range(1,N-K+1):
  sub=q[K+i]-q[i]
  if sub>=maxi:
    maxi=sub
print((maxi+K)/2)

Submission status: Accepted

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

EV_acc = [0] + list(itertools.accumulate([(i+1)/2 for i in p]))

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = lambda x: 0.5*(x+1)
if k == 1:
    res = e(max(p))
else:
    s = [0]
    s[0] = sum(p[:k])
    for i in range(1, n-k+1):
        s.append(s[i-1] - p[i-1] + p[i+k-1])
    idx = s.index(max(s))
    res = sum([e(p[i]) for i in range(idx, idx+k)])
print(res)

Submission status: Accepted

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


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n, k = input_list()
    a = input_list()
    kitais = [0]
    for i in range(n):
        kitai = (a[i]+1)/2
        kitais.append(kitais[i] + kitai)
    ans = 0
    for i in range(n-k+1):
        ans = max(ans, kitais[i+k] - kitais[i])
    print(ans)

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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

tmp = [(i+1)/2 for i in p]
# cs = list(np.cumsum(tmp))

cs = [0]*n
cs[0] = tmp[0]
for i in range(len(tmp)-1):
    cs[i + 1] = cs[i] + tmp[i + 1]

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

l = [i for i in range(1, 1001)]
av = np.cumsum(l) / l

tmp = [av[i - 1] for i in p]
cs = list(np.cumsum(tmp))

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

Submission status: Accepted

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

score = sum(P[:K])
mmax = score
idx = 0
for i in range(1, N-K+1):
  score = score - P[i-1] + P[i+K-1]
  if score > mmax:
    mmax = score
    idx = i
  else:
    continue

print((K+mmax)/2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,K=map(int, input().split())
P = list(map(int, input().split()))

S = []

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

tmp = sum(S[:K])
ans = tmp

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


print(ans)

Submission status: Accepted

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

from itertools import accumulate
acc = list(accumulate(p))

ans = 0
for st in range(n-k+1):
    ans=max(acc[k+st]-acc[st],ans)
    
print((ans+k)/2)

Submission status: Accepted

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

ans = 0.0
k = 0
v = 0.0
for i in range(N):
    v += (P[i] + 1) / 2
    k += 1
    if k > K:
        v -= (P[i-K] + 1) / 2
        k -= 1
    ans = max(ans, v)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
maxI = 0
maxT = 0
t = 0
for i in range(n):
    t += p[i]
    if k <= i:
        t -= p[i-k]
    if maxT < t:
        maxT = t
        maxI = i
ans = 0


def calc(n):
    return n*(n+1)/2/n
    ans = 0
    for i in range(1, n+1):
        ans += i/n
    return ans


for i in range(maxI-k+1, maxI+1):
    #print(i, p[i])
    ans += calc(p[i])
# print(p)
#print(maxT, maxI)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

values = [0]

for p in P:
    values.append(values[-1] + (p * (p + 1) // 2 / p))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n,k = map(int,input().split())
l = [0] + list(map(int,input().split()))
for i in range(n):
    l[i+1] = (l[i+1]+1)/2
acc = list(accumulate(l))
# print(acc)
maxi = 0
for i in range(n-k+1):
    maxi = max(maxi,acc[i+k]-acc[i])
print(maxi)

Submission status: Accepted

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

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

sum1 = sum(p[:k])
num = k-1
max1 = sum1

for i in range(k,n):
    sum1 = sum1 - p[i-k] + p[i]
    if sum1 >= max1:
        max1 = sum1
        num = i
    #print(max1,sum1,i)

sum2 = sum(p[num-k+1:num+1])

def goukei(j):
    return 1/2 * j * (j+1)

print(float((goukei(sum2)-goukei(k-1))/(sum2 -k +1)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    p = [int(x) for x in input().split()]
    a = [(x+1)*x//2/x for x in p]
    ans = 0
    sm = 0
    for i in range(n):
        sm += a[i]
        if i + 1 >= k:
            ans = max(ans, sm)
            sm -= a[i - k + 1]
    print(ans)



    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

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

def cul(x):
    ans = (1 + x)*x/(2*x)
    return ans

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

pn1 = p - 1

ans = sum(pn1[:K])
spb = ans
for i in range(N-K):
    sp = spb -pn1[i] + pn1[i+K]
    #print(sp,spb,pn1[i],pn1[i+K])
    ans = max(sp,ans)
    spb = sp
print(ans/2+K)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
exp0 = (sum(p[:K])+K)/2
MAX=exp0
old = exp0
for i in range(1,N-K+1):
  new = old + (p[K+i-1]+1)/2 - (p[i-1]+1)/2
  if new > MAX: MAX = new
  old = new
print(MAX)

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
c=list(map(int, input().split()))
l =[]
ans = 0

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

cb = list(map(abc,c))

s = sum(cb[:b])
l.append(s)

for i in range(b,a):
    s = s - cb[i-b] + cb[i]
    l.append(s)

L = sorted(l)
print(L[-1])

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = tuple(accumulate(map(int, input().split())))
ans = P[K - 1]
for i in range(N - K):
  ans = max(P[i + K] - P[i], ans)
print((ans + K) / 2)

Submission status: Accepted

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

S = [0]
sum_ = 0
for i, p in enumerate(P):
  sum_ += p
  S.append(sum_)


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

res = (max_sum + K) / 2

print(res)

Submission status: Accepted

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

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

sumEx=[0]*(n+1)
for i in range(n):
  sumEx[i+1]=sumEx[i]+ex[p[i]]

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    e_value = [(1 + i)/2 for i in p]
    c_value = [e_value[0]]
    for i in range(1, n):
        c_value.append(c_value[i-1] + e_value[i])
    ans = 0
    for i in range(k-1, n):
        if i == k-1:
            ans = c_value[i]
        else:
            ans = max(ans, c_value[i]-c_value[i-k])
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = tuple(map(int, input().split()))
P2 = P[K:]

max_sum = 0
sum_ = sum(P[:K])

for p, q in zip(P, P2):
  max_sum = max(max_sum, sum_)
  sum_ += q - p
  
max_sum = max(max_sum, sum_)
          
res = (max_sum + K)/ 2
print(res)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string,scipy
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N,K = LI()
    P = LI()
    Pe = [(v+1)/2 for v in P]
    P_ms = numpy.cumsum(Pe)
    if K==N:print("{:.12f}".format(sum(Pe)));exit(0)
    ans = 0
    for i in range(K,N):
        ans = max(ans,P_ms[i]-P_ms[i-K])
    print("{:.12f}".format(ans))
main()

Submission status: Accepted

Solution code:
expected = {}

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

max_sum = 0
for i in range(k):
  max_sum += p[i]
  
last_sum = max_sum
max_init_index = 0

for i in range(1, n - k + 1):
  current_sum = last_sum - p[i - 1] + p[i + k - 1]
  if max_sum < current_sum:
    max_sum = current_sum
    max_init_index = i
  last_sum = current_sum

for i in range(1, 1001):
  expected[i] = 1 + (i - 1)/2

ans = 0
for i in range(max_init_index, max_init_index + k):
  ans += expected[p[i]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


s=[]
p=np.array(p)
sum=0
for i in range(n):
  sum+=(1+p[i])/2
  s.append(sum)
#print(s)
if k==n:
  print(s[-1])
  exit()
max=s[k-1]-s[0]
for j in range(1,n-k):
  #print(j)
  if max<= s[j+k]-s[j]:
    max=s[j+k]-s[j]
  
print(max)

Submission status: Accepted

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

P = [int(_) for _ in input().split()]

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

ans = 0
tmp = 0
for i in range(N):
    tmp += P[i]
    if i < K - 1: continue
    ans = max(tmp, ans)
    tmp -= P[i - K + 1]
print(ans)

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(0).read().split())
b=[q+1 for q in a]
ans=sum(b[:k])
now=ans
for i in range(k,n):
  now=now+b[i]-b[i-k]
  ans=max(ans,now)
print(ans/2)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
a = [(i+1)/2 for i in rl()]
a = [0] + list(accumulate(a))
ans = 0
for i in range(n-k+1):
    ans = max(ans, a[i+k] - a[i])
print(ans)

Submission status: Accepted

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,k = MAP()

p = LIST()
#
# i=0
# j = k-1

mx = 0

for i in range(k):
    mx+=(p[i]+1)/2
    # print(mx)
gndMax = mx
i = 1
j=k
# print(mx)
while(j<n):
    mx = mx + (p[j] + 1) / 2 - (p[i - 1] + 1) / 2
    gndMax=max(gndMax, mx)
    i+=1
    j+=1
    # print(mx, gndMax)
print(gndMax)

Submission status: Accepted

Solution code:

from itertools import accumulate
def resolve():
    def ev(x):
        return (x*(x+1)//2)/x

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

    E = [0]+[ev(a) for a in A]
    E = list(accumulate(E))
    ans = 0
    for i in range(N-K+1):
        if ans < E[i+K] - E[i]:
            ans = E[i + K] - E[i]
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

(n, k), s, res, sm = map(int, input().split()), list(map(lambda x: (int(x) + 1) / 2, input().split())), 0, 0
for i in range(n):
	if i < k: sm += s[i]
	else: sm += s[i]; sm -= s[i-k]
	res = max(res, sm)
print(f'{res:.10f}')
# print(f'{max([sum(s[i:i+k]) for i in range(n - k + 1)]):.10f}')

Submission status: Accepted

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

for i in range(n - k):
  expected_value.append(expected_value[-1]-p[i]+p[i+k])
print((max(expected_value)+k)/2)

Submission status: Accepted

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

def main():
    n, k = map(int, input().split())
    inlis = tuple(map(int, input().split()))
    kitalis = list(map(kitaichi, inlis))
    kitadic = {}
    kitadic[0] = kitalis[0] 
    for i in range(1, n):
        kitadic[i] = kitadic[i-1] + kitalis[i]
       
    tmp = 0
    if n == k:
        print(kitadic[n-1])
    else:
        for i in range(n - k):
            atai = kitadic[i+k] - kitadic[i]
            if tmp < atai:
                tmp = atai
        print(tmp)
        exit()



    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K, *X = map(int, open(0).read().split())

y = [float(x * (x + 1) / 2 / x) for x in X]
ans = sum(y[:K])
res = ans
for i in range(K, N):
    res = res - y[i - K] + y[i]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

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

pre = sum(plist[:K])
ans = pre
for i in range(0, N-K):
    pre = pre - plist[i] + plist[i+K]
    ans = max(ans, pre)

print((ans + K)/2)

Submission status: Accepted

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

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

pos_acum = list(itertools.accumulate(pos))

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

Submission status: Accepted

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

P_ac = [sum(P[:k])]
for i in range(n-k):
    P_ac.append(P_ac[-1]-P[i]+P[i+k])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
A=[]
for num in P:
    num=(num+1)*0.5
    A.append(num)

T=sum(A[:K])
ans=sum(A[:K])
for i in range(N-K):
    a=T-A[i]+A[i+K]
    ans=max(ans,a)
    T=a
print(ans)

Submission status: Accepted

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

def main():
	n,k=MI()
	p=LI()

	for i in range(n):
		p[i]=p[i]/2+0.5
	#print(p)

	ans=sum(p[:k])
	now=sum(p[:k])

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















if __name__ == "__main__":
	main()