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:
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l0=LI()
  l=copy.deepcopy(l0)

  for i in range(1,n):
    l[i]+=l[i-1]

  l=[0]+l
  n+=1
  l2=[]

  for i in range(k,n):
    l2.append(l[i]-l[i-k])

  ind=l2.index(max(l2))
  ans=0

  for i in range(ind,ind+k):
    x=l0[i]
    ans+=(((1+x)*x)/2)/x
    # print(ans)

  return ans

# main()
print(main())

Submission status: Accepted

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

Submission status: Accepted

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

s=sum(P[:K])
tmp=s
k=0
for i in range(N-K):
    s=s-P[i]+P[K+i]
    
    if tmp<s:
        k=i+1
        tmp=s
ans=0
for i in range(k,k+K):
    ans+=(P[i]+1)/2

print(ans)

Submission status: Accepted

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

S = sum(P[0:K])
O = [S]
for i in range(N-K):
    S = S + P[K+i] - P[i]
    O.append(S)

print(max(O))

Submission status: Accepted

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

EP = [(p+1)*0.5 for p in P]


ans = sum(EP[:K])
now = ans
for i in range(N-K):
  now = now - EP[i] + EP[i+K]
  ans = max(ans, now)


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

t = sum(m[0:K])
result = t
for i in range(N - K):
    t -= m[i]
    t += m[i + K]
    if t > result:
        result = t
print(result)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n,k = m()


a = l()


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

co = sum(aaa[:k])

ma = co
for i in range(0,n-k):
    co = co - aaa[i] + aaa[i+k]
    
    ma = max(ma,co)
print(ma)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from fractions import Fraction as F

def solve():
    N, K = map(int,input().split())
    P = list(map(int,input().split()))
    q = sum(P[:K])
    res = q
    for i in range(K,N):
        q += P[i]-P[i-K]
        res = max(res, q)
    return str((res+K)/2)

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

Submission status: Accepted

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

ans = 0
for e in p[0:k]:
  ans += (e + 1) / 2
anses = [ans]

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

print(max(anses))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int, p: "List[int]"):
    ans = 0
    # for i in range(max(1,N),N):
    #     t = p[i]*(p[i]+1)/(2*p[i])
    #     print(t)
    #     ans += t
    pi = [p[i]*(p[i]+1)/(2*p[i]) for i in range(N)]
    api = [0] * (N+1)
    for i in range(N):
        api[i+1] = api[i] + pi[i]
    ans = 0
    for i in range(0, N-K+1):
        ans = max(ans, api[K+i]-api[i])

    print(ans)
    return



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:
n,k,*p=map(int,open(0).read().split())

m=sum(p[0:k])
ans=[m]
for i in range(k,n):
    m=m+p[i]-p[i-k]
    ans.append(m)
print(0.5*(max(ans)+k))

Submission status: Accepted

Solution code:
MOD = 1000000007
INF = float("inf")

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

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

start = 0
end = k-1
cur_sum = sum(A[start:end+1])
ans = cur_sum

for i in range(len(A)-k):
    cur_sum = cur_sum - A[start] + A[end+1]
    ans = max(ans, cur_sum)
    end += 1
    start += 1

print(ans)

Submission status: Accepted

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

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

num = sum(a[:k])
num_max = num
for i in range(k, n):
    num = num-a[i-k]+a[i]
    if num>num_max:
        num_max=num

print((num_max+k)/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = tuple(map(int, input().split()))
tmp = sum(P[:K])
M = tmp
for i in range(N - K):
    tmp += P[i + K]
    tmp -= P[i]
    if M < tmp:
        M = tmp
print((M + K) / 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, K = [int(str) for str in input().strip().split()]
x = [int(str) for str in input().strip().split()]

sums = [0]
for i in x:
    sums.append(sums[-1] + (i + 1) / 2)

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

print(ans)

Submission status: Accepted

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

# 1~p: 期待値は(p+1)/2
s = sum(p[:k])
ans = s
for i in range(k,n):
  s += p[i] - p[i-k]
  ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,k = mi()
p = li()
for i in range(n):
    p[i] = (p[i]+1) / 2
ans = 0
ima = 0
for i in range(k):
    ima += p[i]
ans = ima
for i in range(k,n):
    tmp1 = p[i]
    tmp2 = p[i-k]
    ima = ima +tmp1 -tmp2
    ans = max(ima,ans)
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N, K = MI()
    p = LI()

    ans = 0
    cur = 0
    right = 0
    ans_arr = []
    for left in range(N):

        while right < len(p) and right - left < K:
            cur += p[right]
            right += 1

        if ans <= cur:
            ans = cur
            ans_arr = p[left:right]
        cur -= p[left]
        # print(ans, cur, cur + p[left], left, right)

    # print(ans, ans_arr)
    p = 0

    for a in ans_arr:
        t = (a * (a + 1)) // 2
        # print(a, t)
        p += t / a

    print(p)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum_p = [None] * (n - k + 1)
sum_p[0] = sum(p[0:k])
for i in range(1, n - k + 1):
  sum_p[i] = sum_p[i -1] + p[i + k - 1] - p[i -1]

max_sum_p = max(sum_p)

print((k + max_sum_p) / 2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
p = [int(c) for c in  input().split()]
ans = 0
m = 0
for i in range(K):
  m += (1+p[i])/2
ans = m
for i in range(K,N,1):
  m -= p[i-K]/2
  m += p[i]/2
  if m>ans:
    ans = m
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = sum(p_e[:K])
tmp = ans
i = 0

while 1:
    try:
        ans = max(ans, tmp - p_e[i] + p_e[K + i])
        tmp = tmp - p_e[i] + p_e[K + i]
        i += 1
    except IndexError:
        break

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
ss = [0]*(N+1)

for i in range(N):
    ss[i+1] = ss[i] + s[i]

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

print(ans)

Submission status: Accepted

Solution code:
n,k=[int(j) for j in input().split()]
p=[int(j) for j in input().split()]
from itertools import accumulate
l=[0]+list(accumulate(p))
t=0
a,b=0,0
for i in range(n-k+1):
    if t<l[i+k]-l[i]:
        t=l[i+k]-l[i]
        a,b=i+k,i
ans=0
for i in range(b,a):
    j=p[i]
    ans+=j*(j+1)//2/j
    
print(ans)

Submission status: Accepted

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

e = [0]*n

for i in range(n):
  e[i] = (l[i]+1)/2

from itertools import accumulate
a = [0] + e
b = list(accumulate(a))

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

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    max_sum = 0
    index = -1
    sum_P = [0] + list(accumulate(P))
    for i in range(N + 1 - K):
        tmp = sum_P[i+K] - sum_P[i]
        if tmp > max_sum:
            max_sum = tmp
            index = i
        
    ans = 0
    for i in range(index,index + K):
        tmp = P[i] * (P[i] + 1) // 2
        ans += tmp / P[i]
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
a = IL()
rui = [0]
tmp = 0
for i in range(N):
  tmp += a[i] + 1
  rui.append(tmp)

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

Submission status: Accepted

Solution code:
def A():
    temp = input().split()
    S = temp[0]
    T = temp[1]
    temp = [int(i) for i in input().split()]
    A = temp[0]
    B = temp[1]
    U = input()
    if U == S:
        print(A-1, B)
    else:
        print(A, B-1)

def B():
    print('x'*len(input()))

def C():
    N = int(input())
    A = [int(i) for i in input().split()]
    if N > len(set(A)):
        print('NO')
    else:
        print('YES')

def D():
    temp = [int(i) for i in input().split()]
    N = temp[0]
    K = temp[1]
    p = [int(i) for i in input().split()]
    expected_val = [(i+1)/2.0 for i in p]
    cur = sum(expected_val[:K])
    ans = cur
    for i in range(N-K):
        cur -= expected_val[i]
        cur += expected_val[i+K]
        ans = max(ans, cur)
    print(ans)

D()

Submission status: Accepted

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

    max_val = 0
    val = 0
    count = 0
    start = 0
    for i in arr:
        val += i
        count += 1
        if count == k:
            max_val = max(max_val,val)
            count -= 1
            val -= arr[start]
            start += 1

    print(max_val)

main()

Submission status: Accepted

Solution code:
[N,K] = list(map(int,input().split()))
P = list(map(int,input().split()))
EP = []
for i in range(N):
    EP.append((P[i]+1)/2)

SP = [0]*(N-K+1)
S0 = 0
for j in range(K):
    S0 += EP[j]
SP[0] = S0
for i in range(1,len(SP)):
    SP[i] = SP[i-1]+EP[i+K-1]-EP[i-1]

print(max(SP))

Submission status: Accepted

Solution code:
from itertools import accumulate

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

pc = [0] * N

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

L = [0] + list(accumulate(pc))

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(k):
    ans += (1+a[i])/2
answer = ans
for i in range(k, len(a)):
    ans = ans + (a[i]+1)/2 - (a[i-k]+1)/2
    if ans > answer:
        answer = ans
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

current = ans

for i in range(K, N):
    diff = p[i] - p[i-K]
    temp = current + diff
    if temp >  ans:
        ans = temp
    current = temp

print ans

Submission status: Accepted

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

kitai=[]
for i in p:
  kitai.append((i+1)/2)

ans=sum(kitai[0:k])
temp=ans


for i in range(0,n-k):
  temp+=kitai[k+i]-kitai[i]
  ans=max(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
def to_cumsum(arr, pad=True):
    """
    1次元配列を累積和の1次元配列に変換する
    pad: 先頭に0の項を作る場合はTrue
    """
    cumsum = 0
    padding = 1 if pad else 0
    new = [0] * (len(arr) + padding)
    for i, e in enumerate(arr):
        cumsum += e
        new[i + padding] = cumsum
    return new


N, K = MI()
P = LMI()
cum = to_cumsum(P, pad=True)

t = 0
for i in range(N - K + 1):
    m = cum[i + K] - cum[i]
    t = max(t, m)
print((t + K) / 2)

Submission status: Accepted

Solution code:
def main():

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

    v = []
    for i in range(N):
        v.append(p[i]*(p[i]+1)/p[i]/2)

    # print(v)
    u = sum(v[:K])
    max_u = u
    # print(u)
    for i in range(K, N):
        u += v[i] - v[i-K]
        # print(u)
        max_u = max(max_u, u)
    return max_u


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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    m = e = sum(P[:K])
    c = 0
    for i in range(N - K):
        e = e + P[K + i] - P[i]
        if e > m:
            m = e
            c = i + 1
    t = sum((k + 1) for k in P[c:c + K]) / 2
    print(t)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

N, K, *P = map(int, open(0).read().split())

E = [(p + 1) for p in P]

A = [0] + list(accumulate(E))

print("{:.8f}".format(max(A[i + K] - A[i] for i in range(N - K + 1)) / 2))

Submission status: Accepted

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

s = [0]
sum_ = 0
for i in range(1, 1001):
    sum_ += i
    s.append(sum_)

b = []
for i in range(n):
    b.append(s[p[i]] / p[i])

bcum = [0] * (n+1)
for i in range(n):
    bcum[i+1] = bcum[i] + b[i]

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

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
p=list(map(int,input().split()))
#p=sorted(p,reverse=True)
saidai=0

for i in range(n):
    p[i]=(p[i]+1)/2
#print(p)
gokei=0
for i in range(k):
    gokei+=p[i]
saidai=gokei
for i in range(1,n-k+1):
    gokei+=p[i+k-1]-p[i-1]
    #print(gokei)
    saidai=max(saidai,gokei)

print(saidai)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
P=[(int(i)+1)/2 for i in input().split()]
S=[P[0]]
for i in range(n-1):
    S.append(S[i]+P[i+1])
ans=0
S.insert(0,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()))

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

curr = best_score
for i in range(N-K):
    curr += p[i+K] + 1
    curr -= p[i] + 1
    if curr > best_score:
        best_score = curr

print(best_score/2)

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    E = [(p*(p+1)//2)/p for p in P]
    S = [0]*(N+1)
    ma = 0
    for i in range(N):
        S[i+1] = S[i] + E[i]
    for i in range(N-K+1):
        ma = max(ma, S[K+i] - S[i])
    print(ma)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

T=sum(p[0:k])
S=T
num=0

for i in range(n-k):
    T-=p[i]
    T+=p[k+i]
    if T>S:
        S=T
        num=i+1

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

ans=0
for i in p[num:num+k]:
    ans+=kitai(i)

print(ans)

Submission status: Accepted

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

sm = sum(pn[:k])
maxi = sm
for i in range(n-k):
  sm -= pn[i]
  sm += pn[i+k]
  maxi = max(maxi, sm)
print((maxi + k) / 2.0)

Submission status: Accepted

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

sum_p = [0]

for p in P:
    sum_p.append(sum_p[-1] + p)

max_sum = 0
for i in range(K, N+1):
    buf = sum_p[i] - sum_p[i-K]
    if buf > max_sum:
        max_sum = buf

print((max_sum + K) / 2)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
p_v = {i:sum([1/i*j for j in range(1,i+1)]) for i in range(1, 1001)}
p = [p_v[one] for one in p]

sums = [sum(p[:K])]
for i in range(1,N-K+1):
    sums.append(sums[-1]-p[i-1]+p[i+K-1])
print(max(sums))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, k, *p = map(int, sys.stdin.read().split())

def main():
    ex = [(1 + i) * i // 2  / i for i in p]
    l = 0; r = k

    res = []
    s = sum(ex[l:r])
    res.append(s)
    while r < n:
        s -= ex[l]
        s += ex[r]
        l += 1
        r += 1
        res.append(s)
    return max(res)
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

i = 0
s = 0
while i < K:
	s += p_list[i]
	i += 1

m = 0
while True:
	if m < s:
		m = s
	if i == N:
		break
	s += p_list[i] - p_list[i - K]
	i += 1

print((K + m) / 2)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from collections import deque

N,K = II()
p = III()
x = [(p0+1)/2 for p0 in p]

d = deque(x[:K])
ans = sum(d)
now = sum(d)
for i in range(K,N):
    now = now-x[i-K]+x[i]
    if now>ans:
        ans = now

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
x=[0]
for i in range(n):
  x.append(p[i]+x[-1])
l=[]
for i in range(n-k+1):
  l.append(x[i+k]-x[i])
print(max(l))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def ii(): return int(input())
def iis(): return input().split()
def imi(): return map(int,iis())
def iil(): return list(imi())

n, k = imi()
p = iil()
li = [0]
for i in range(n):
    li.append(li[i]+(1+p[i])/2)
ans = 0
for i in range(n-k+1):
    ans = max(ans, li[i+k]-li[i])
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
measuring = [sum(P[:K])]
for i in range(K, N):
    measuring.append(measuring[-1]+P[i]-P[i-K])
# print(measuring)

pointa = measuring.index(max(measuring))

tmp = P[pointa:pointa+K]
# print(tmp)
ans = 0
for t in tmp:
    ans += (t+1)/2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**9

n, k = map(int, input().split())
p = [int(item) for item in input().split()]
total = 0
for i in range(k):
    total += p[i]
max_t = total
l = 0; r = k
for i in range(k, n):
    total += p[i] - p[i-k]
    if total > max_t:
        max_t = total
        l = i - k
        r = i

print(0.5 * k + max_t / 2.0)

Submission status: Accepted

Solution code:
from collections import deque

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

Q = deque([(p + 1) / 2 for p in ps[:K]])

max_ = sum(Q)
now = max_
for p in ps[K:]:
    p = (p + 1) / 2
    head = Q.popleft()
    now = now - head + p
    Q.append(p)
    max_ = max(max_, now)

print(max_)

Submission status: Accepted

Solution code:
n,k = (int(num) for num in input().split())
p = [int(num) for num in input().split()]
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = cum[i] + p[i]
ans = 0
#print(cum)
for j in range(n-k+1):
    t = cum[j+k] - cum[j]
    if t > ans:
        ans = t
print((ans+k)/2)

Submission status: Accepted

Solution code:


#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,k = mi()
    p = li()

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

    tmpl = [0]
    tmp = 0
    for i in range(len(p)):
        tmp+=p[i]
        tmpl.append(tmp)

    #print("c")

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

    print(ans)



main()

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
P = np.array([0] + lr())
P = (P+1) / 2
Pcum = P.cumsum()
X = Pcum[K:] - Pcum[:-K]
answer = X.max()
print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def get_sum(a, b, c):
    """ 等差数列の和：(初項a, 末項b, 項数c) """
    return (a+b) * c // 2

N, K = MAP()
A = LIST()

B = [0] * N
for i in range(N):
    B[i] = get_sum(1, A[i], A[i]) / A[i]

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
P=list(map(int,input().split()))
#kこの和
sum_k=sum(P[:k])
ans=[sum_k]
for i in range(n-k):
    temp=ans[-1]
    temp-=P[i]
    temp+=P[k+i]
    ans.append(temp)
print(k/2+max(ans)/2)

Submission status: Accepted

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

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

tot = sum(exp[:K])
max_tot = tot
for i in range(N-K):
    tot += exp[i+K]- exp[i]
    if tot > max_tot:
        max_tot = tot
        
print(max_tot)

Submission status: Accepted

Solution code:
from itertools import accumulate

N,K = [int(zz) for zz in input().split()]
P = [int(zz) for zz in input().split()]

Q = [0] + list(accumulate(P))
ans = 0
for i in range(N-K+1):
    ans = max(ans,Q[i+K]-Q[i])

print((ans+K)/2)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = [int(x) for x in input().split()]
for i, p in enumerate(P):
  P[i] = (p + 1) / 2
ans = 0
E = 0
for i, p in enumerate(P):
  E += p
  if K <= i:
    E -= P[i - K]
  ans = max(E, ans)
print(ans)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,k=MI()
    pp=LI()
    ev=[]
    for p in pp:
        ev.append((p+1)/2)
    mx=0
    cur=0
    for i in range(n):
        cur+=ev[i]
        if i-k>=0:cur-=ev[i-k]
        if cur>mx:mx=cur
    print(mx)

main()