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

#dice.sort(reverse=True)
MAXX = 1001
ave = [0.0]*MAXX

ans = 0.0
right = 0
#sumz = [0.0]*(N+1)
# #累積和
# for i in range(N):
#     x = dice[i]
#     if ave[x] <= 0.000001:
#         ave[x] = (x + 1) / 2.0
#     sumz[i+1] = sumz[i]+ ave[x]
#
# #find max
# for i in range(K, N+1):
#     if ans < sumz[i] - sumz[i-K]:
#         ans = sumz[i] - sumz[i-K]
#
# print(ans)
#
sumz = 0.0
for left in range(0, N):
    if right <= left: right = left+1
    while right <= N and right - left <= K:
        x = dice[right-1]
        if ave[x] <= 0.000001:
            ave[x] = (x+1)/2.0
        sumz += ave[x]
        right += 1

    if ans < sumz:
        ans = sumz

    sumz -= ave[dice[left]]

print(ans)

Submission status: Accepted

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

#dice.sort(reverse=True)
MAXX = 1001
ave = [0.0]*MAXX

ans = 0.0
sumz = [0.0]*(N+1)
right = 0
#累積和
for i in range(N):
    x = dice[i]
    if ave[x] <= 0.000001:
        ave[x] = (x + 1) / 2.0
    sumz[i+1] = sumz[i]+ ave[x]

#find max
for i in range(K, N+1):
    if ans < sumz[i] - sumz[i-K]:
        ans = sumz[i] - sumz[i-K]

print(ans)
#
# for left in range(0, N):
#     if right <= left: right = left
#     while right < N and right - left <= K:
#         x = dice[right-1]
#         if ave[x] <= 0.000001:
#             ave[x] = (x+1)/2.0
#         sumz[right] = sumz[right-1] + ave[x]
#         right += 1
#
#     if ans < sumz[right-1]:
#         ans = sumz[right-1]
#
# print(ans)
#
#
#
#
#
# print(ans)

Submission status: Accepted

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

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

d = defaultdict(float)
for i in range(1, 1001):
    j = i
    while 0 < j:
        t = j * (1 / i)
        d[i] += t
        j -= 1

sum = [0.0]*(n+1)
for i in range(n):
    sum[i+1] = sum[i] + d[p[i]]

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

print('{:.12f}'.format(ans))

Submission status: Accepted

Solution code:
import sys
from builtins import enumerate
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目 n = int(input())
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n, k = map(int, input().split())
    p_s = [0] + list(map(int, input().split()))

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

    ans = 0
    val = 0
    for i in range(1, len(p_s)):
        val += avr_s[p_s[i]]
        if i < k:
            continue
        elif i == k:
            ans = val
        else:
            val -= avr_s[p_s[i - k]]
            ans = max(ans, val)

    print(ans)


# テストクラス


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5 3
1 2 2 4 5"""
        output = """7.000000000000"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """4 1
6 6 6 6"""
        output = """3.500000000000"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10 4
17 13 13 12 15 20 10 13 17 11"""
        output = """32.000000000000"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
A = [(p + 1) / 2 for p in P]
B = [0 for i in range(N)]
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i - 1] + A[i]
ans = 0
for i in range(K - 1, N):
    if i == K - 1:
        a = B[i]
    else:
        a = B[i] - B[i - K]
    if ans < a:
        ans = a
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
p = [0] + list(map(lambda x: int (x) + 1, input().split()))
cum = list(accumulate(p))
res = 0
for i in range(len(p)-k):
    res = max(res, cum[i+k] - cum[i])
print(res / 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print((k+ans)/2)

Submission status: Accepted

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

s=sum(m[:k])
mx=s
for i in range(1,n-k+1):
    s-=m[i-1]
    s+=m[i+k-1]
    mx=max(mx,s)
print((mx+k)/2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *P = map(int, read().split())

    csum = [0]
    csum.extend(accumulate(P))

    ans = 0
    for i in range(N - K + 1):
        if ans < csum[i + K] - csum[i]:
            ans = csum[i + K] - csum[i]

    print((K + ans) / 2)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *P = map(int, read().split())

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

    ans = 0
    for i in range(N - K + 1):
        if ans < csum[i + K] - csum[i]:
            ans = csum[i + K] - csum[i]

    print((K + ans) / 2)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
licsum = [0]
for i in range(n):
    licsum.append(licsum[i] + li[i])
lia = []
for i in range(n-k+1):
    a = licsum[k+i] - licsum[i] + k
    lia.append(float(a)/2)
print(max(lia))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[43]:


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


# In[44]:


le = [(x+1)/2 for x in p]
e = sum(le[:K])
ans = e
for i in range(N-K):
    e -= le[i]
    e += le[i+K]
    ans = max(ans ,e)
print(ans)


# In[ ]:

Submission status: Accepted

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


N, K = map(int, input().split())
p = list(map(int, input().split()))
prev = ev(p[0])
ans = sum([ev(i) for i in p[:K]])
total = ans

for i in range(1, N-K+1):
    total -= prev
    total += ev(p[i+K-1])
    prev = ev(p[i])
    ans = max(ans, total)

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
pList = list(map(int, input().split()))
#範囲内の和を求めるには累積和とういうのを使う
#事前準備
cum_sum_list = [0]*(N+1)
cum_sum = 0
pListLen = len(pList)
for i in range(pListLen):
  cum_sum += pList[i]
  cum_sum_list[i+1] = cum_sum
#範囲内の和を比べていく
max_sumK = 0
max_start = 0
max_end = 0
for i in range(N-K+1):
  start = i
  end = (i+K)
  sumK = cum_sum_list[end] - cum_sum_list[start]
  if (sumK > max_sumK):
    max_sumK = sumK
    max_start = start
    max_end = end
#最大の期待値を計算して出力
answer = 0
for num in pList[max_start:max_end]:
  answer += sum(list(range(1, (num+1))))/num
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0] * n

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
m=0

for i in range(n):
    b[i]=(a[i]+1)/2

c=sum(b[:k])
m=c
for i in range(n-k):
    c-=b[i]
    c+=b[k+i]
    m=max(m,c)
print(m)

Submission status: Accepted

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

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

e = sum(le[:k])
m = e
for i in range(n - k):
    e -= le[i]
    e += le[k + i]
    m = max(m, e)

print(m)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, K = map(int, input().split())
P = [0]+list(map(int, input().split()))
Psum = list(accumulate(P))
total = 0
for i in range(K, N+1):
    if Psum[i]-Psum[i-K] > total:
        total = Psum[i]-Psum[i-K]
        index = i
ans = 0
for i in range(index, index-K, -1):
    ans += (P[i]+1)*0.5

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
P_sum = 0

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

for j in range(K):
  P_sum += P[j]

ans = P_sum
for t in range(K, N):
  P_sum -= P[t - K]
  P_sum += P[t]
  ans = max(ans, P_sum)

print(ans)

Submission status: Accepted

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

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

    for i in range(len(P)):
        P[i] = ( P[i] + 1 ) / 2

    max = sum(P[:K])
    add = max
    for i in range(len(P)-K):
        add = add + P[i+K] - P[i]
        if add > max:
            max = add
    print(max)


main_sum()

Submission status: Accepted

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

m = prev = sum(P[:k])
s = 0
for i in range(1, n - k + 1):
    tmp = prev - P[i - 1]+ P[i + k - 1]
    prev = tmp
    if tmp > m:
        s = i
    m = max(tmp, m)

ans = 0
d = dict()
for i in range(s, s + k):
    p = P[i]
    if p not in d.keys():
        tmp = sum(range(p + 1)) / p
        ans += tmp
        d[p] = tmp
    else:
        ans += d[p]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from statistics import median

N, K = [int(x) for x in input().split()]
line_in_dice = list([(int(x) + 1) / 2 for x in input().split()])

result = [0] * (N + K)

result[0] = line_in_dice[0]
result[K] -= line_in_dice[0]

max_point = 0
max_value = 0

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

print(max(result))

Submission status: Accepted

Solution code:
from statistics import median
from time import time

t = time()

N, K = [int(x) for x in input().split()]
line_in_dice = list([int(x) for x in input().split()])

result = [0] * (N + K)

result[0] = line_in_dice[0]
result[K] -= line_in_dice[0]

max_point = 0
max_value = 0

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

    if result[i] > max_value:
        max_point = i
        max_value = result[i]


def create_median(x):
    if x % 2 == 1:
        return (1 + x) // 2
    else:
        return ((x // 2) + (x // 2 + 1)) / 2


print(sum(create_median(x)
          for x in line_in_dice[max_point - K + 1: max_point+1]))

Submission status: Accepted

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

sum_reg = (sum(p[0:k])+k)/2
max_reg = sum_reg
for i in range(k, n):
  sum_reg = sum_reg + (p[i]-p[i-k])/2
  max_reg = max(max_reg, sum_reg)
  
print(max_reg)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
p=list(map(int,input().split()))
expection=[0]*N
for i in range(N):
    expection[i]=(p[i]+1)/2
accumulation=[0]*(N+1)
for i in range(N):
    accumulation[i+1]=accumulation[i]+expection[i]
ans=0
for i in range(N-K+1):
    ans=max(ans,accumulation[i+K]-accumulation[i])
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(n):
  s[i] = (p[i]+1)/2

# 期待値を累積していく
p = [0]*(n+1)
for i in range(1, n+1):
  p[i] = p[i-1] + s[i-1]

# 下記の方法で隣接する期待値合計を取得し、比較を行う。
# 隣接する期待値の合計　= 対象とする範囲の最大累積和　- 対象外範囲の最大累積和
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())
ps = list(map(int, input().split()))
    
s = [0]*(n+1)
 
for i in range(n):
    s[i+1] = s[i] + (ps[i] + 1)/2
 
    
tmp=0
for i in range(n-k+1):
    tmp=max(tmp, s[i+k] - s[i])

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

Submission status: Accepted

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

Submission status: Accepted

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

temp = sum(p[:K])
ind = 0
ma = 0

for i in range(N - K):
    temp = temp - p[i] + p[i + K]
    if temp > ma:
        ind = i + 1
        ma = temp

def calc_e(N):
    ans = 0
    for j in range(1, N + 1):
        ans += j / N
    return ans

ans = 0
for i in range(K):
    ans += calc_e(p[ind + i])
print(ans)

Submission status: Accepted

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

ex_p = [(pi+1)/2 for pi in pN]
cum_p = [ex_p[0]]
for i in range(1,N):
    cum_p.append(cum_p[i-1]+ex_p[i])

max_ex = cum_p[K-1]
for i in range(1,N-K+1):
    if max_ex < cum_p[K+i-1] - cum_p[i-1]:
        max_ex = cum_p[K+i-1] - cum_p[i-1]

print(max_ex)

Submission status: Accepted

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


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

Submission status: Accepted

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

a = list(map(int,input().split()))
sum_a = [0]

for i in range(K):
    sum_a[0] += a[i]

j = 0

max_v = sum_a[0]
ele = K-1
expected_value = 0
# 範囲の初めの値と範囲外の値を比較
for i in range(K,N):
    sum_a.append(sum_a[j]+(a[i]-a[i-K]))
    if max_v < sum_a[j+1]:
        max_v = sum_a[j+1]
        ele = i
    j += 1
s_ele = ele+1-K
for n in range(s_ele,ele+1):
    expected_value += (a[n]*0.5)+0.5
print(expected_value)

Submission status: Accepted

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

Submission status: Accepted

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

def expectation(N):
    # exp = 0
    # for i in range(1, N+1):
    #     exp += i/N
    # return exp
    return N/2+0.5

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

Es = [(P+1)/2 for P in Ps]
accEs = list(accumulate([0]+Es))

ans = 0.0
for i in range(N-K+1):
    e = accEs[i+K] - accEs[i]
    if e > ans:
        ans = e

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
P = inl()


def solve():
    ex = 0.0
    for i in range(K):
        ex += (P[i] + 1) / 2
    mex = ex
    for i in range(K, N):
        j = i - K
        ex += (P[i] + 1) / 2
        ex -= (P[j] + 1) / 2
        if mex < ex:
            mex = ex
    return mex


print(solve())

Submission status: Accepted

Solution code:
N , K = map(int, input().split())
p = list(map(int, input().split()))
Etop = 0
E = 0
q = []
Ruiseki = 0
S = []
Top = 0
for i in p:
    q.append((i+1) / 2)

for E in q:
    Ruiseki += E
    S.append(Ruiseki)

if N == K:
    print(S[N-1])
    quit()
else:
    for j in range(N-K):
        Sig = S[K+j] - S[j]
        if Sig > Top:
            Top = Sig

print(Top)

Submission status: Accepted

Solution code:
from itertools import accumulate
from decimal import Decimal
n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[0]
tmp=0
for i in range(n):
    p[i]=Decimal((p[i]+1)/2)
    tmp+=p[i]
    l.append(tmp)
ans=0
for i in range(k,n+1):
    tmp=l[i]-l[i-k]
    if tmp>ans:
        ans=tmp
print(Decimal(ans))

Submission status: Accepted

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

Submission status: Accepted

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

ans=(sum(P[:K])+K)/2
now=ans
i=K
while i<N:
    now=now+(P[i]+1)/2-(P[i-K]+1)/2
    ans=max(now,ans)
    i+=1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

s = sum(p[:k])
best = (s, 0)
for i in range(1,n-k+1):
    s = s - p[i-1] + p[i+k-1]
    if s>best[0]:
        best = (s, i)
        
ans = sum((p[i]+1)/2 for i in range(best[1], best[1]+k))
print(ans)

Submission status: Accepted

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

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

s = [0]*(n+1)

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

res = 0

for i in range(n-k+1):
    res = max(res, s[i+k] - s[i])
    
print("{:.10f}".format(res))

Submission status: Accepted

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

cand = [a]
for i in range(n-k):
  a -= p[i]
  a += p[i+k]
  cand.append(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inf = int(1e9+7)
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    n, k = [int(x) for x in raw_input().split()]
    
    arr = [(1 + float(x)) / 2 for x in raw_input().split()]
    
    if k == 1:
        print(max(arr))
        return
    
    #print(arr)
    """
    total = sum(probs)
    
    arr = [0] * n
    
    for i in range(n):
        arr[i] = float(i) * (probs[i] / total)
    
    print(arr)
    """
    
    pref_sum = [0] * n
    
    pref_sum[0] = arr[0]
    
    for i in range(1, n):
        pref_sum[i] = pref_sum[i-1] + arr[i]
    
    #print(pref_sum)
    
    max_sub = -inf
    
    for end in range(k-1, n):
        start = end - k + 1
        # length = end - (end - k) + 1 = k + 1
        cur = pref_sum[end] # - pref_sum[start-1]
        if start > 0:
            cur -= pref_sum[start-1]
        if cur > max_sub:
            max_sub = cur
        
    
    
    print(max_sub)

main()

Submission status: Accepted

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

Submission status: Accepted

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

# 累積和
c = [0] * (n+1)
for i in range(n):
  c[i+1] = c[i] + p[i]
#print(c)
mx = 0
mx_i = -1
for i in range(n-k+1):
  st = c[i+k] - c[i]
  if st > mx:
    mx = st
    mx_i = i
ans = 0
for i in range(mx_i, mx_i+k):
  a = p[i]
  ans += ((a * (a+1)) // 2) / a
print(ans)
# print(mx_a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = (int(a) for a in input().split())
p = list((int(a) + 1)/2 for a in input().split())
s = [sum(p[:K])]

for i in range(N-K) :
    s.append(s[-1] - p[i] + p[i+K])
print(max(s))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

sumK = sum(A[0:K])

L = [sumK]

for i in range (0, N-K):
	sumK = sumK + A[K+i] - A[i]
	L.append(sumK)

print(max(L))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
from itertools import accumulate
def main():
    n, k, *p = map(int, read().split())
    p2 = [(1 + pe) /2 for pe in p]
    p2a = tuple(accumulate(p2))
    r = p2a[k-1]
    for i1 in range(k, n):
        r = max(r, p2a[i1] - p2a[i1-k])
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K= map(int, input().split())
List = list(map(int, input().split()))
num=0
s=0
for i in range(K):
    s+=(List[i]+1)
num=0
#print(s)
if N==K:
    print(s/2)
else:
    
    for i in range(N-K):
        a=List[i+K]-List[i]
        #print(a)
        n1=s+a
        s=n1
        n1=n1/2
        if n1>=num:
            num=n1
    print(num)

Submission status: Accepted

Solution code:
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
p = list(map(int, input().split()))

expected_value =[(i+1)/2 for i in p] #各さいころの期待値

#隣接する数列の和
adjacent_sum =[0]*N
adjacent_sum[0] =sum(expected_value[:K])
ans =[0]*N
ans[0] =adjacent_sum[0]
for i in range(1,N-K+1):
    adjacent_sum[i] =adjacent_sum[i-1] -expected_value[i-1] +expected_value[i+K-1]
    ans[i] =adjacent_sum[i] 
print(max(ans))

Submission status: Accepted

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

ans = [(sum(p[:k])+k)/2]

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

Submission status: Accepted

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

num = 0
for j in range(k):
    num += p[j]
l.append(num)

for i in range(n-k):
    l.append(l[i]-p[i]+p[i+k])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

s = [0]*(len(P)+1)
for i in range(len(P)):
    s[i+1] = s[i]+e_p[i]
    
res = 0
for i in range(n-k+1):
    res = max(res,s[i+k] - s[i])
        
print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split()) #KはN以下
P = list(map(int,input().split()))
for i,p in enumerate(P):
    P[i] = (p+1)/2
q = [0]
for p in P:
    q.append(q[-1]+p)
s,e = 0,K
ans = q[K]-q[0]
while e<len(q):
    ans = max(ans,q[e]-q[s])
    s += 1
    e += 1
print(ans)