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) = list(map(int,input().split()))
P = list(map(int, input().split()))

def max_expected(L, K):
  length = len(L)
  if (length < K):
    return -1
  if (length == K):
    return (sum(L) + K) / 2
  mid = length // 2
  s_left = max_expected(L[0:mid], K)
  s_right = max_expected(L[mid:], K)
  offset = 0

  if (mid - K + 1 < 0):
    offset = - (mid - K + 1)
  end_offset = 0
  if (mid + K - 1 >= length):
    end_offset = mid + K - 1 - length
  max_p = sum(L[mid - K + 1 + offset:mid + 1 + offset])
  prev = max_p
  for i in range(mid - K + 1 + offset + 1, mid - end_offset):
    prev = prev - L[i - 1] + L[i + K - 1]
    if max_p < prev:
      max_p = prev
  
  return max((max_p + K) / 2, s_left, s_right)
print("{}".format(max_expected(P, K)))

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    n, k = map(int, stdin.readline().split())
    p = list(map(int, stdin.readline().split()))

    sp = [0] * 1001

    for i in range(1, 1001):
        sp[i] = sum(range(i + 1)) / i

    summary = [0] * n
    summary[0] = sp[p[0]]
    for i in range(1, n):
        summary[i] = summary[i - 1] + sp[p[i]]

    max = summary[k - 1]
    for i in range(k, n):
        tmp = summary[i] - summary[i - k]
        if tmp > max:
            max = tmp
    print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
import numpy as np

n, k = map(int, input().split())
p = np.array(list(map(int, input().split())), dtype="i8")
p = np.insert(np.cumsum((1 + p) / 2), 0, 0)
print((p[k:] - p[:n - k + 1]).max())

Submission status: Accepted

Solution code:
from itertools import accumulate
import numpy as np

n, k = map(int, input().split())
p = np.array(list(map(int, input().split())), dtype=np.int64)

p = (1 + p) / 2
p = [0] + list(accumulate(p))
ans = 0
for i in range(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()))
E = [(p+1) / 2 for p in P]

s = sum(E[:K])
ans = s
for i, e in enumerate(E[K:]):
    s = s - E[i] + e
    ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
import itertools
from itertools import accumulate

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

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

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

def range_sum(l, r):
    return csum[r] - csum[l]

ret = 0
for i in range(n - k + 1):
    ret = max(ret, range_sum(i, i + k))
print(ret)

Submission status: Accepted

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

p_=[]
for i in range(len(p)):
  p_.append((1+p[i])/2)
 
import itertools
c=list(itertools.accumulate(p_))

ans=0
if N!=K:
  
  for i in range(0,N-K):
    s=c[i+K]-c[i]
    ans=max(ans,s)
else:
  ans=c[K-1]
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(0, N-K+1):
    tmp = acc[i+K] - acc[i]
    if tmp > ans:
        ans = tmp
    
print((ans+K)/2)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
num_list =list(map(int,input().split()))
sum_list = [0]
sum_di = []
sum = 0

for i in range(N):
    x= (num_list[i]+1)/2
#    print(x)
    sum =sum + x
    sum_list.append(sum)

for i in range(N-K+1):
    sum_di.append(sum_list[K+i]-sum_list[i])
#   print(sum_list)
#    print(sum_di)

print(max(sum_di))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
D = [0]+[(p+1)/2 for p in P]
res = 0
for i in range(N+1):
    res += D[i]
    if i>=K:
        res-=D[i-K]
        ans = max(res,ans)
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
a=0
for i in range(k):
  a+=p[i]
b=[a]
for j in range(1,n-k+1):
  c=b[j-1]-p[j-1]+p[j+k-1]
  b.append(c)
b.sort(reverse=True)
print(b[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
E = list(map(lambda x: (x + 1) * 0.5, list(map(int, input().split()))))
e = sum(E[:k])
emax = e
for i in range(k, n):
    e += E[i] - E[i - k]
    emax = max(e, emax)
print(emax)

Submission status: Accepted

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

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

S = [0 for _ in range(N + 1)]

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

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

print(ans)

Submission status: Accepted

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

S = [0 for _ in range(N + 1)]

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

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

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dice = [int(p) for p in input().split()]
S = [ 0 for i in range(n+1)]

for i in range(1, n+1):
  S[i] = S[i-1] + (dice[i-1]+1)/2.0
  #期待値計算

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

Submission status: Accepted

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

def get_val(a):
    return (1+a)/2

current = 0
for i in range(k):
    current += get_val(p_list[i])
max = current

for i in range(k, n):
    current -= get_val(p_list[i-k])
    current += get_val(p_list[i])
    if max < current:
        max = current

print(max)

Submission status: Accepted

Solution code:
def main():
    N,K=map(int, input().split())
    A = list(map(int, input().split()))
    S = (sum(A[0:K])+K)/2
    S_max=S
    for i in range(K,N):
        S +=  A[i]/2
        S -= A[i-K]/2
        if S_max<S:
            S_max=S
    print(S_max)

main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, k = Is()
P = LI()
P_ = [(x+1)/2 for x in P]

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

print(ans)

Submission status: Accepted

Solution code:
n,m=(int(i) for i in input().split())
l=[]
for i in input().split():
  l.append((int(i)+1)/2)
s=sum(l[0:m])
maxe=s
for i in range(n-m):
  s+=l[m+i]
  s-=l[i]
  if s>maxe:
    maxe=s
print(maxe)

Submission status: Accepted

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

from collections import deque

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

d_front = deque(p[:k])
d_back = deque(p[k:])

sum_prev = sum(d_front)
ma = sum_prev

while d_back:
    ff = d_front.popleft()
    bf = d_back.popleft()
    sum_curr = sum_prev - ff + bf
    ma = max(ma, sum_curr)
    d_front.append(bf)
    sum_prev = sum_curr
    
print(ma)

Submission status: Accepted

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

p = [0]*1001
for i in range(1, 1001):
    p[i] = p[i-1] + i
pn = list(map(lambda x: p[x] / x, pn))

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

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
max = 0
list = [0] * k
evlist = [0] * 1000
for i in range(1000):
    wk = 0
    for j in range(i + 1):
        wk += j + 1
    evlist[i] = float(wk / (i + 1))
wk = 0
start = 0
for i in range(n - (k - 1)):
    if wk == 0:
        for j in range(i, i + k):
            wk += p[j]
    else:
        wk += p[i + k - 1]
        wk -= p[i - 1]
    if max < wk:
        max = wk
        start = i
for i in range(start, start + k):
    list[i - start] = p[i]
ans = 0
for i in range(k):
    ans += evlist[list[i] - 1]
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
max = 0
list = [0] * k
evlist = [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0,
          11.5, 12.0, 12.5, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5, 17.0, 17.5, 18.0, 18.5, 19.0, 19.5, 20.0,
          20.5, 21.0, 21.5, 22.0, 22.5, 23.0, 23.5, 24.0, 24.5, 25.0, 25.5, 26.0, 26.5, 27.0, 27.5, 28.0, 28.5, 29.0,
          29.5, 30.0, 30.5, 31.0, 31.5, 32.0, 32.5, 33.0, 33.5, 34.0, 34.5, 35.0, 35.5, 36.0, 36.5, 37.0, 37.5, 38.0,
          38.5, 39.0, 39.5, 40.0, 40.5, 41.0, 41.5, 42.0, 42.5, 43.0, 43.5, 44.0, 44.5, 45.0, 45.5, 46.0, 46.5, 47.0,
          47.5, 48.0, 48.5, 49.0, 49.5, 50.0, 50.5, 51.0, 51.5, 52.0, 52.5, 53.0, 53.5, 54.0, 54.5, 55.0, 55.5, 56.0,
          56.5, 57.0, 57.5, 58.0, 58.5, 59.0, 59.5, 60.0, 60.5, 61.0, 61.5, 62.0, 62.5, 63.0, 63.5, 64.0, 64.5, 65.0,
          65.5, 66.0, 66.5, 67.0, 67.5, 68.0, 68.5, 69.0, 69.5, 70.0, 70.5, 71.0, 71.5, 72.0, 72.5, 73.0, 73.5, 74.0,
          74.5, 75.0, 75.5, 76.0, 76.5, 77.0, 77.5, 78.0, 78.5, 79.0, 79.5, 80.0, 80.5, 81.0, 81.5, 82.0, 82.5, 83.0,
          83.5, 84.0, 84.5, 85.0, 85.5, 86.0, 86.5, 87.0, 87.5, 88.0, 88.5, 89.0, 89.5, 90.0, 90.5, 91.0, 91.5, 92.0,
          92.5, 93.0, 93.5, 94.0, 94.5, 95.0, 95.5, 96.0, 96.5, 97.0, 97.5, 98.0, 98.5, 99.0, 99.5, 100.0, 100.5, 101.0,
          101.5, 102.0, 102.5, 103.0, 103.5, 104.0, 104.5, 105.0, 105.5, 106.0, 106.5, 107.0, 107.5, 108.0, 108.5,
          109.0, 109.5, 110.0, 110.5, 111.0, 111.5, 112.0, 112.5, 113.0, 113.5, 114.0, 114.5, 115.0, 115.5, 116.0,
          116.5, 117.0, 117.5, 118.0, 118.5, 119.0, 119.5, 120.0, 120.5, 121.0, 121.5, 122.0, 122.5, 123.0, 123.5,
          124.0, 124.5, 125.0, 125.5, 126.0, 126.5, 127.0, 127.5, 128.0, 128.5, 129.0, 129.5, 130.0, 130.5, 131.0,
          131.5, 132.0, 132.5, 133.0, 133.5, 134.0, 134.5, 135.0, 135.5, 136.0, 136.5, 137.0, 137.5, 138.0, 138.5,
          139.0, 139.5, 140.0, 140.5, 141.0, 141.5, 142.0, 142.5, 143.0, 143.5, 144.0, 144.5, 145.0, 145.5, 146.0,
          146.5, 147.0, 147.5, 148.0, 148.5, 149.0, 149.5, 150.0, 150.5, 151.0, 151.5, 152.0, 152.5, 153.0, 153.5,
          154.0, 154.5, 155.0, 155.5, 156.0, 156.5, 157.0, 157.5, 158.0, 158.5, 159.0, 159.5, 160.0, 160.5, 161.0,
          161.5, 162.0, 162.5, 163.0, 163.5, 164.0, 164.5, 165.0, 165.5, 166.0, 166.5, 167.0, 167.5, 168.0, 168.5,
          169.0, 169.5, 170.0, 170.5, 171.0, 171.5, 172.0, 172.5, 173.0, 173.5, 174.0, 174.5, 175.0, 175.5, 176.0,
          176.5, 177.0, 177.5, 178.0, 178.5, 179.0, 179.5, 180.0, 180.5, 181.0, 181.5, 182.0, 182.5, 183.0, 183.5,
          184.0, 184.5, 185.0, 185.5, 186.0, 186.5, 187.0, 187.5, 188.0, 188.5, 189.0, 189.5, 190.0, 190.5, 191.0,
          191.5, 192.0, 192.5, 193.0, 193.5, 194.0, 194.5, 195.0, 195.5, 196.0, 196.5, 197.0, 197.5, 198.0, 198.5,
          199.0, 199.5, 200.0, 200.5, 201.0, 201.5, 202.0, 202.5, 203.0, 203.5, 204.0, 204.5, 205.0, 205.5, 206.0,
          206.5, 207.0, 207.5, 208.0, 208.5, 209.0, 209.5, 210.0, 210.5, 211.0, 211.5, 212.0, 212.5, 213.0, 213.5,
          214.0, 214.5, 215.0, 215.5, 216.0, 216.5, 217.0, 217.5, 218.0, 218.5, 219.0, 219.5, 220.0, 220.5, 221.0,
          221.5, 222.0, 222.5, 223.0, 223.5, 224.0, 224.5, 225.0, 225.5, 226.0, 226.5, 227.0, 227.5, 228.0, 228.5,
          229.0, 229.5, 230.0, 230.5, 231.0, 231.5, 232.0, 232.5, 233.0, 233.5, 234.0, 234.5, 235.0, 235.5, 236.0,
          236.5, 237.0, 237.5, 238.0, 238.5, 239.0, 239.5, 240.0, 240.5, 241.0, 241.5, 242.0, 242.5, 243.0, 243.5,
          244.0, 244.5, 245.0, 245.5, 246.0, 246.5, 247.0, 247.5, 248.0, 248.5, 249.0, 249.5, 250.0, 250.5, 251.0,
          251.5, 252.0, 252.5, 253.0, 253.5, 254.0, 254.5, 255.0, 255.5, 256.0, 256.5, 257.0, 257.5, 258.0, 258.5,
          259.0, 259.5, 260.0, 260.5, 261.0, 261.5, 262.0, 262.5, 263.0, 263.5, 264.0, 264.5, 265.0, 265.5, 266.0,
          266.5, 267.0, 267.5, 268.0, 268.5, 269.0, 269.5, 270.0, 270.5, 271.0, 271.5, 272.0, 272.5, 273.0, 273.5,
          274.0, 274.5, 275.0, 275.5, 276.0, 276.5, 277.0, 277.5, 278.0, 278.5, 279.0, 279.5, 280.0, 280.5, 281.0,
          281.5, 282.0, 282.5, 283.0, 283.5, 284.0, 284.5, 285.0, 285.5, 286.0, 286.5, 287.0, 287.5, 288.0, 288.5,
          289.0, 289.5, 290.0, 290.5, 291.0, 291.5, 292.0, 292.5, 293.0, 293.5, 294.0, 294.5, 295.0, 295.5, 296.0,
          296.5, 297.0, 297.5, 298.0, 298.5, 299.0, 299.5, 300.0, 300.5, 301.0, 301.5, 302.0, 302.5, 303.0, 303.5,
          304.0, 304.5, 305.0, 305.5, 306.0, 306.5, 307.0, 307.5, 308.0, 308.5, 309.0, 309.5, 310.0, 310.5, 311.0,
          311.5, 312.0, 312.5, 313.0, 313.5, 314.0, 314.5, 315.0, 315.5, 316.0, 316.5, 317.0, 317.5, 318.0, 318.5,
          319.0, 319.5, 320.0, 320.5, 321.0, 321.5, 322.0, 322.5, 323.0, 323.5, 324.0, 324.5, 325.0, 325.5, 326.0,
          326.5, 327.0, 327.5, 328.0, 328.5, 329.0, 329.5, 330.0, 330.5, 331.0, 331.5, 332.0, 332.5, 333.0, 333.5,
          334.0, 334.5, 335.0, 335.5, 336.0, 336.5, 337.0, 337.5, 338.0, 338.5, 339.0, 339.5, 340.0, 340.5, 341.0,
          341.5, 342.0, 342.5, 343.0, 343.5, 344.0, 344.5, 345.0, 345.5, 346.0, 346.5, 347.0, 347.5, 348.0, 348.5,
          349.0, 349.5, 350.0, 350.5, 351.0, 351.5, 352.0, 352.5, 353.0, 353.5, 354.0, 354.5, 355.0, 355.5, 356.0,
          356.5, 357.0, 357.5, 358.0, 358.5, 359.0, 359.5, 360.0, 360.5, 361.0, 361.5, 362.0, 362.5, 363.0, 363.5,
          364.0, 364.5, 365.0, 365.5, 366.0, 366.5, 367.0, 367.5, 368.0, 368.5, 369.0, 369.5, 370.0, 370.5, 371.0,
          371.5, 372.0, 372.5, 373.0, 373.5, 374.0, 374.5, 375.0, 375.5, 376.0, 376.5, 377.0, 377.5, 378.0, 378.5,
          379.0, 379.5, 380.0, 380.5, 381.0, 381.5, 382.0, 382.5, 383.0, 383.5, 384.0, 384.5, 385.0, 385.5, 386.0,
          386.5, 387.0, 387.5, 388.0, 388.5, 389.0, 389.5, 390.0, 390.5, 391.0, 391.5, 392.0, 392.5, 393.0, 393.5,
          394.0, 394.5, 395.0, 395.5, 396.0, 396.5, 397.0, 397.5, 398.0, 398.5, 399.0, 399.5, 400.0, 400.5, 401.0,
          401.5, 402.0, 402.5, 403.0, 403.5, 404.0, 404.5, 405.0, 405.5, 406.0, 406.5, 407.0, 407.5, 408.0, 408.5,
          409.0, 409.5, 410.0, 410.5, 411.0, 411.5, 412.0, 412.5, 413.0, 413.5, 414.0, 414.5, 415.0, 415.5, 416.0,
          416.5, 417.0, 417.5, 418.0, 418.5, 419.0, 419.5, 420.0, 420.5, 421.0, 421.5, 422.0, 422.5, 423.0, 423.5,
          424.0, 424.5, 425.0, 425.5, 426.0, 426.5, 427.0, 427.5, 428.0, 428.5, 429.0, 429.5, 430.0, 430.5, 431.0,
          431.5, 432.0, 432.5, 433.0, 433.5, 434.0, 434.5, 435.0, 435.5, 436.0, 436.5, 437.0, 437.5, 438.0, 438.5,
          439.0, 439.5, 440.0, 440.5, 441.0, 441.5, 442.0, 442.5, 443.0, 443.5, 444.0, 444.5, 445.0, 445.5, 446.0,
          446.5, 447.0, 447.5, 448.0, 448.5, 449.0, 449.5, 450.0, 450.5, 451.0, 451.5, 452.0, 452.5, 453.0, 453.5,
          454.0, 454.5, 455.0, 455.5, 456.0, 456.5, 457.0, 457.5, 458.0, 458.5, 459.0, 459.5, 460.0, 460.5, 461.0,
          461.5, 462.0, 462.5, 463.0, 463.5, 464.0, 464.5, 465.0, 465.5, 466.0, 466.5, 467.0, 467.5, 468.0, 468.5,
          469.0, 469.5, 470.0, 470.5, 471.0, 471.5, 472.0, 472.5, 473.0, 473.5, 474.0, 474.5, 475.0, 475.5, 476.0,
          476.5, 477.0, 477.5, 478.0, 478.5, 479.0, 479.5, 480.0, 480.5, 481.0, 481.5, 482.0, 482.5, 483.0, 483.5,
          484.0, 484.5, 485.0, 485.5, 486.0, 486.5, 487.0, 487.5, 488.0, 488.5, 489.0, 489.5, 490.0, 490.5, 491.0,
          491.5, 492.0, 492.5, 493.0, 493.5, 494.0, 494.5, 495.0, 495.5, 496.0, 496.5, 497.0, 497.5, 498.0, 498.5,
          499.0, 499.5, 500.0, 500.5]
wk = 0
start = 0
for i in range(n - (k - 1)):
    if wk == 0:
        for j in range(i, i + k):
            wk += p[j]
    else:
        wk += p[i + k - 1]
        wk -= p[i - 1]
    if max < wk:
        max = wk
        start = i
for i in range(start, start + k):
    list[i - start] = p[i]
ans = 0
for i in range(k):
    ans += evlist[list[i] - 1]
print(ans)

Submission status: Accepted

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

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

for j in range(K):
  s += p[j]

x = s
 
for k in range(N - K):
  t = s - p[k] + p[K + k]
  if max(s, x) <= t:
    x = t
  else:
    pass
  s = t

print(x)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    dice = [int(p) for p in input().split()]
    S = [ 0 for i in range(N+1)]

    for i in range(1, N+1):
        S[i] = S[i-1] + (dice[i-1]+1)/2.0

    max_E = 0
    for i in range(N-K+1):
       E = S[i+K] - S[i]
       if max_E < E:
           max_E = E

    print(max_E)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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

acc=list(accumulate(p))
ans=sum(p[:k])
for i in range(k,n):
    ans=max(ans, acc[i]-acc[i-k])
print(ans/2+0.5*k)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

acc=list(accumulate(p))
# print(acc)
ans=0
if n==k:
    print(sum(p)/2+0.5*k)
    exit()
for i in range(k,n):
    ans=max(ans,acc[i]-acc[i-k])
print(ans/2+0.5*k)

Submission status: Accepted

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


for i in range(N):
    S[i+1] = S[i] + P[i]

right = 0
left  = 0
ans   = 0
for i in range(N-K+1):

    if ans <= (S[i+K]-S[i]):
        ans = (S[i+K]-S[i])
        right = i+K
        left  = i

ans = 0
for j in range(left, right, 1):
    ans = ans + (1+P[j])
print(ans/2)

Submission status: Accepted

Solution code:
M,N = list(map(int,input().split()))
s = list(map(int,input().split()))
count = 0
kiroku = 0

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


for i in range(N,M+1):
    count = max(count,t[i]-t[i-N])

print(count)

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
#4317
p=list(map(int,input().split()))
def keisan(x):
  return (k+x)/2
ans=0
zzz=list(itertools.accumulate(p))
zzz.insert(0,0)
han=0
for i in range(k,len(zzz)):
  if han<zzz[i]-zzz[i-k]:
    han=zzz[i]-zzz[i-k]
print(keisan(han))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
N,K = map(int, stdin.readline().rstrip().split())
P = list(map(int, stdin.readline().rstrip().split()))

Q = [(p+1)/2 for p in P]
c = [0]
for q in Q:
    c.append(c[-1] + q)

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

Submission status: Accepted

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

su = [0] * (n + 1)

for i in range(n):
    su[i + 1] = su[i] + ((lis[i] + 1) / 2)

res = 0
for j in range(n - k + 1):
    res = max(res, su[j + k] - su[j])   
print(res)

Submission status: Accepted

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

su = [0] * (n + 1)

for i in range(n):
    su[i + 1] = su[i] + ((lis[i] + 1) / 2)

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

Submission status: Accepted

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

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

e_list = [get_e(p[i]) for i in range(N)]
c_e_list = [0 for i in range(N)]
c_e_list[0] = e_list[0]
for i in range(1, N):
    c_e_list[i] = c_e_list[i-1] + e_list[i]

max_e = c_e_list[K-1]
for i in range(1, N-K+1):
    e = c_e_list[i+K-1] - c_e_list[i-1]
    if e > max_e:
        max_e = e

print(max_e)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=sum([p[i] for i in range(k)])
if n==k:
  ans=l
else:
  ans=0
for i in range(n-k):
  l-=p[i]
  l+=p[i+k]
  ans=max(l,ans)
print('{:.12f}'.format((ans+k)/2))

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split(' ')))
    P = list(map(int, input().split(' ')))
    means = [(p + 1) / 2 for p in P]
    max_mean = sum(means[:K])
    current_mean = max_mean
    next_head = K
    while next_head < N:
        diff = means[next_head] - means[next_head - K]
        current_mean += diff
        max_mean = max([max_mean, current_mean])
        next_head += 1
    print(max_mean)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
p = map(lambda x: sum(range(1,x+1))/x, p)
 
l = [0]
for i,v in enumerate(p):
    prev = l.pop()
    l.append(prev)
    l.append(prev + v)
 
ans = 0
for i in range(k, len(l)):
    tmp = l[i] - l[i-k]
    if ans < tmp:
        ans = tmp
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate([(x+1)/2 for x in p])) # 累積和を計算
 
ans = max(acc[i]-acc[i-k] for i in range(k, n+1)) # k番目からn番目まで計算
print(ans)

Submission status: Accepted

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

V = [0] * (N + 1)
S = [0] * (1010)
for i in range(1009):
    S[i + 1] = S[i] + (i + 1)
# print(S)

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

# print(V)

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

print(res)

Submission status: Accepted

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

s = sum(p[:K])
mx = s
for i in range(N - K):
    j = i + K
    s += p[j] - p[i]
    if mx < s:
        mx = s

print((mx + K) / 2)

Submission status: Accepted

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

e_p = []
for i in range(n):
    e_p.append(0.5*p[i]+0.5)


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

Submission status: Accepted

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

Submission status: Accepted

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

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

    tmp_max = sum(P[:K])
    tmp = sum(P[:K])
    for i in range(N-K):
        tmp += P[i+K]
        tmp -= P[i]

        if tmp > tmp_max:
            tmp_max = tmp

    print((tmp_max + K) / 2)

main()

Submission status: Accepted

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

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

sum_list = [0 for _ in range(N)]
for i in range(N):
  sum_list[i] = sum_n(L[i]) / L[i]

st = 0
ed = K - 1
tmp = sum(sum_list[:ed+1])
ans = tmp
for i in range(N - K):
  ed += 1
  tmp = tmp - sum_list[st] + sum_list[ed]
  ans = max(ans, tmp)
  st += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

p_exp = [(p[i] + 1)/2 for i in range(n)]

s = [0]
for i in range(n):
    s.append(s[i] + p_exp[i])

ans = -1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a=sum(p[0:K])
array.append(a)

for n in range(N-K):
  a=a-p[n]+p[n+K]
  array.append(a)

ans=(max(array)+K)/2
print(ans)

Submission status: Accepted

Solution code:
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

N,K = map(int,input().split())
def kitai(num):
    return (1+int(num))/2
P = list(map(kitai,input().split()))	  

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

Submission status: Accepted

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


def solve(N: int, K: int, p: "List[int]"):
    sums = [0]
    maxsum = 0
    for i in range(0, N):
        sums.append(p[i] + sums[i])

    for i in range(0, N - K + 1):
        maxsum = max(sums[i + K] - sums[i], maxsum)
    print((maxsum + K) / 2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np


N,K = map(int,input().split())
pn = list(map(int, input().split()))
sumn = list(map(lambda x:x*(x+1)/2/x ,pn))

ans = []
k_sum = sum(sumn[:K])
ans.append(k_sum)
for k in range(1,len(sumn)-K+1):
  k_sum -= sumn[k-1]
  k_sum += sumn[k+K-1]
  ans.append(k_sum)
print(max(ans))

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()]
c = [0] + list(accumulate(p))
mx = 0
mx_n = 0
for i in range(len(c)-k):
    if mx < c[i+k] - c[i]:
        mx = c[i+k] - c[i]
        mx_n = i
ans = 0
for i in range(k):
    ans += (p[mx_n + i] + 1) / 2

print(ans)

Submission status: Accepted

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

def get_expectation (x):
    return (float(x)+1)/2
exp = list(map(get_expectation,input().split()))


total = sum(exp[0:K])
maxim = total
for i in range(K,N):
    total -= exp[i-K]
    total += exp[i]
   
    
    if maxim <= total:
        maxim = total

print("%.10f" % maxim)

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] *(n+1)
ma = 0
cnt = 0
for i in range(k):
    cnt += p[i]
ma =cnt
for i in range(n):
    if i+k >= n:
        break
    cnt += p[i+k]
    cnt -= p[i]
    ma = max(ma,cnt)
print(ma)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
A = [(1+int(x))/2 for x in input().split()]
wa = []
w = 0
for i in range(0,K):
    w = w+A[i]
wa.append(w)
for j in range(N-K):
    w = w + A[j+K] - A[j]
    wa.append(w)
print(max(wa))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
E = list(map(lambda x: (x + 1) * 0.5, list(map(int, input().split()))))
esum = sum(E[:k])
ans = esum
for i in range(n - k):
    esum = esum - E[i] + E[i + k]
    ans = max(ans, esum)
print(ans)