Problem:


最大の和  

問題

n 個の整数からなる数列 a1, a2, ..., an と正整数 k (1 ≤ k ≤ n) が与えられる.このとき, 連続して並ぶ k 個の整数の和  Si = ai + ai+1 + ... + ai+k-1 (1 ≤ i ≤ n - k + 1) の最大値を出力するプログラムを作りなさい.

入力

input.txt である.-->
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．入力は２つのゼロを含む行で終了する．

 1 行目には正整数 n (1 ≤ n ≤  100000) と正整数 k (1 ≤ k ≤ n) がこの順に空白で
区切られて書かれている.2 行目以降の第 1 + i 行目 (1 ≤ i ≤ n) には, 数列の i 番目の項 ai (-10000 ≤ ai ≤ 10000) が書かれている.
 採点用データのうち, 配点の 60% 分は n ≤ 5000, k ≤ 1000 を満たす.

データセットの数は 5 を超えない．

出力

output.txt である.
output.txt は 1 行だけからなり,その 1 行は Si の最大値だけを含む.
-->
データセットごとにSi の最大値を１行に出力する．

入出力例

入力例

5 3
2
5
-4
10
3
0 0

出力例

11

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
5 3
2
5
-4
10
3
0 0


Sample output:
11

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n==0 and k==0:
        break
    else:
        a=[int(input()) for _ in range(n)]
        s=sum(a[0:k])
        ss=[s]
        for i in range(k,n):
            s = s+a[i]-a[i-k]
            ss.append(s)
        print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n == 0and k == 0:
        break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k,n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k,n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input())for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    li=[]
    for i in range(n):
        li.append(int(input()))
    s_li=[li[0]]
    for i in range(1,n):
        s_li.append(s_li[-1]+li[i])
    c_li=[s_li[m-1]]
    for i in range(n-m):
        c_li.append(s_li[i+m]-s_li[i])
    print(max(c_li))

Submission status: Accepted

Solution code:
x=[]
y=[]
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    else:
        x=[int(input()) for i in range(n)]
        if len(x)<k:
            pass
        else:
            s=sum(x[0:k])
            y.append(s)
            for i in range(0,n-k):
                s=s-x[i]+x[i+k]
                y.append(s)
            print(max(y))

Submission status: Accepted

Solution code:

while True:
    n,k=map(int,input().split())
    if n == 0 and k == 0:break
    a=[int(input())for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if (n,k)==(0,0):
        break
    a=[int(input()) for i in range(n)]
    b=sum(a[0:k])
    c=[b]
    for i in range(n-k):
        b+=a[i+k]-a[i]
        c.append(b)
    print(max(c))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for b in range(n)]
    s=sum(a[0:k])
    t=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        t.append(s)
    print(max(t))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n == 0 and k == 0:break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n, k = [int(i) for i in input().split()]
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    max = s
    for i in range(k, n):
        s = s + a[i] - a[i - k]
        if s > max:
            max = s
    print(max)

Submission status: Accepted

Solution code:
while True:
    n,k = map(int, input().split())
    if n == 0 and k == 0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
        b = 0
    for i in range(k):
        b += a[i]
        s = b
    for i in range(k, n):
        b += a[i]
        b -= a[i - k]
        s = max(s, b)
    print(s)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    x=[]
    for i in range(n):
        x.append(int(input()))
    s=sum(x[0:k])
    max=s
    for i in range(k,n):
        s=int(s+x[i]-x[i-k])
        if max<s:
            max=s
    print(max)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:

    n,k = map(int,input().split())
    if n==0 and k==0 :
        break
    x=[int(input()) for _ in range(n)]
    y=sum(x[0:k])
    z=[y]
    for i in range(k,n):
        y=y+x[i]-x[i-k]
        z.append(y)
    print(max(z))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while 1:
  s=input()
  N, K = map(int, s.split(' '))
  if N == 0 and K == 0:
    break
  a = []
  for _ in range(N):
    a.append(int(input()))
  s = [0]
  for i, n in enumerate(a):
    s.append(n + s[i])

  ans = 0
  for i, n in enumerate(s):
    if i - K >= 0:
      ans = max(ans, s[i] - s[i-K])
  print(ans)

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    N, K = (int(i) for i in input().split())
    while N != 0 or K != 0:
        A = [int(input()) for i in range(N)]
        S = list(accumulate([0] + A))
        ans = 0
        for i in range(N-K+1):
            cur = S[i+K] - S[i]
            ans = max(ans, cur)
        print(ans)
        N, K = (int(i) for i in input().split())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

a, s = [0]*100003, [0]*100003
while True:
	n, k = map(int, input().split())
	if n == 0: break
	s[0] = a[0] = int(input())
	for i in range(1, n):
		a[i] = int(input())
		s[i] = s[i-1] + a[i]
		if i >= k: s[i] -= a[i-k]
	ans = s[k-1]
	for i in range(k, n):
		if s[i] > ans: ans = s[i]
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 & k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k =map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n , k = map(int,input().split())
    if (n,k) == (0,0): break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    l = [s]
    for i in range(k,n):
        s = s + a[i] - a[i-k]
        l.append(s)
    print(max(l))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
while True:
    n,k=map(int,input().split())
    if n+k==0:
        break
    a=[int(input()) for i in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:


a, s = [0]*100003, [0]*100003
while True:
	n, k = map(int, input().split())
	if n == 0: break
	s[0] = a[0] = int(input())
	for i in range(1, n):
		a[i] = int(input())
		s[i] = s[i-1] + a[i]
		if i >= k: s[i] -= a[i-k]
	ans = s[k-1]
	for i in range(k, n):
		if s[i] > ans: ans = s[i]
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,(input().split()))
    if n==0 and k==0:
        break
    a,b,s=[],[],0
    for i in range(n):
        a.append(int(input()))
        if i==k-1:
            s=sum(a[0:k])
        elif i>=k:
            s=s+a[i]-a[i-k]
        b.append(s)
    print(max(b))

Submission status: Accepted

Solution code:
while True:
    n, k = [int(i) for i in input().split()]
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    max = s
    for i in range(k, n):
        s = s + a[i] - a[i - k]
        if s > max:
            max = s
    print(max)

Submission status: Accepted

Solution code:
while True :
    n,k = map(int,input().split())
    if n == 0 and k == 0 :
        break
    a = 0
    x = [ ]
    for i in range (n):
        y = int(input())
        x.append(y)
    b = 0
    for j in range (k):
        b += x[j]
    S = [ ]
    S.append(b)
    for i in range (1,n-k+1):
        b = S[i-1] + x[i+k-1] - x[i-1]
        S.append(b)
    print(max(S))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    
    a=[int(input()) for i in range(n)]
    b=sum(a[0:k])
    c=[b]
    for j in range(k,n):
        b=b+a[j]-a[j-k]
        c.append(b)
    print(max(c))

Submission status: Accepted

Solution code:
while True:
    n,k=[int(i) for i in input().split()]
    if n==0 and k==0:
        break
    a=[int(input()) for i in range(n)]
    s=sum(a[0:k])
    max=s
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        if s>max:
            max=s
    print(max)

Submission status: Accepted

Solution code:
a, s = [0]*100003, [0]*100003
while True:
	n, k = map(int, input().split())
	if n == 0: break
	s[0] = a[0] = int(input())
	for i in range(1, n):
		a[i] = int(input())
		s[i] = s[i-1] + a[i]
		if i >= k: s[i] -= a[i-k]
	ans = s[k-1]
	for i in range(k, n):
		if s[i] > ans: ans = s[i]
	print(ans)

Submission status: Accepted

Solution code:
a,s= [0]*100003, [0]*100003
while True:
	n,k=map(int, input().split())
	if n==0:break
	s[0]=a[0]=int(input())
	for i in range(1,n):
		a[i]=int(input())
		s[i]=s[i-1]+a[i]
		if i>=k:s[i]-=a[i-k]
	ans=s[k-1]
	for i in range(k,n):
		if s[i]>ans:ans=s[i]
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n, k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k,n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
  
    s=sum(a[0:k])
    ss=[s]
 
    for i in range(k,n):
            
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k = [int(x) for x in input().split()]
    if n==0 and k==0:
        break

    a = [int(input()) for i in range(n)]

    s = sum(a[0:k])
    max = s

    for i in range(k,n):
        s = s + a[i] - a[i - k]
        if s > max: 
            max = s

    print(max)

Submission status: Accepted

Solution code:
while True:
 n,k = map(int,input().split())
 if n==0 and k==0: break
 
 a = [int(input()) for i in range(n)]

 s = sum(a[0:k])
 max = s

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

Submission status: Accepted

Solution code:
x=[]
y=[]
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    else:
        x=[int(input()) for i in range(n)]
        if len(x)<k:
            pass
        else:
            s=sum(x[0:k])
            y.append(s)
            for i in range(0,n-k):
                s=s-x[i]+x[i+k]
                y.append(s)
            print(max(y))

Submission status: Accepted

Solution code:
while True:
    a,b=map(int,input().split())
    if a==0 and b==0: break
    s=[int(input()) for _ in range(a)]
    S=sum(s[0:b])
    ss=[S]
    for i in range(b,a):
        S=S+s[i]-s[i- b]
        ss.append(S)
    print(max(ss))

Submission status: Accepted

Solution code:
while True :
    n, m = map(int, input().split())
    if m == 0 and n == 0 :
        break
    
    List = []
    max_ans = 0
    sum_ans = 0
    for i in range(n) :
        List.append(int(input()))
        if i < m : 
            sum_ans += List[i] 
        else : 
            sum_ans += List[i] - List[i-m]
        if i >= m - 1 and max_ans < sum_ans :
            max_ans = sum_ans
    print(max_ans)

Submission status: Accepted

Solution code:
while True:
    n, k = [int(i) for i in input().split()]
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    max = s
    for i in range(k, n):
        s = s + a[i]-a[i - k]
        if s > max:
            max = s
    print(max)

Submission status: Accepted

Solution code:
while True:
      n,k=map(int,input().split())
      if n ==0 and k==0:
            break
      a=[int(input()) for _ in range(n)]
      s=sum(a[0:k])
      ss=[s]
      for i in range(k,n):
            s=s+a[i]-a[i-k]
            ss.append(s)
      print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
  
    s=sum(a[0:k])
    ss=[s]
 
    for i in range(k,n):
            
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if (n,k)==(0,0):
        break
    list=[int(input()) for i in range(n)]
    a=[]
    c=0
    for i in range(k):
        c+=list[i]
    a.append(c)
    for j in range(n-k):
        c+=list[k+j]
        c-=list[j]
        a.append(c)
    print(max(a))

Submission status: Accepted

Solution code:
while True:
  n, k = map(int, input().split())
  if n == 0 and k == 0:
    break
  a = [int(input()) for _ in range(n)]
  s = sum(a[0:k])
  ss = [s]
  for i in range(k, n):
    s = s + a[i] - a[i-k]
    ss.append(s)
  print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
   
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
        
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for i in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
  n,k=list(map(int,input().split()))
  if n==0 and k==0:
    break
  a=[]
  for i in range(n):
    a.append(int(input()))
  s=sum(a[0:k])
  t=[s]
  for i in range(k,n):
    s=s+a[i]-a[i-k]
    t.append(s)
  print(max(t))

Submission status: Accepted

Solution code:
while True:
    n, k = map(int, input().split())
    if n == 0 and k == 0: break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss = [s]
    for i in range(k,n):
        s = s +a[i] -a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0: break
    a=[int(input())for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range (k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range (k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    a,b=map(int,input().split())
    if a==0 and b==0: break

    line=[]
    kei=[]
    i=0
    
    for _ in range(a):line.append(int(input()))
    
    for j in range(0,b):i += line[j]
    
    for I in range(b,a):
        i += line[I]-line[I-b]
        kei.append(i)
        
    print(max(kei))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0: break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
  n,k = list(map(int,input().split()))
  if n == 0 and k == 0:
    break
  a=[]
  for i in range(n):
    a.append(int(input()))
  s = sum(a[0:k])
  ss=[s]
  for i in range(k,n):
    s = s +a[i]- a[i-k]
    ss.append(s)
  print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    l = [s]
    for i in range(k,n):
        s = s + a[i] - a[i-k]
        l.append(s)
    print(max(l))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    else:
        a=[int(input())for _ in range(n)]
        s=sum(a[0:k])
        ss=[s]
        for i in range(k,n):
            s=s+a[i]-a[i-k]
            ss.append(s)
        print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n, k = map(int,input().split())
    if n == k == 0:
        break
    data = [int(input()) for _ in range(n)]
    s = sum(data[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + data[i]- data[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    n, k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[]
    max=0
    sum=0
    for i in range(n):
        a.append(int(input()))
        if i<k:
            sum+=a[i]
        else:
            sum+=a[i]-a[i-k]
        if i>=k-1 and max<sum:
            max=sum
    print(max)

Submission status: Accepted

Solution code:
while True:
    n, k = map(int, input().split())
    if n == 0 and k == 0: break
    a = [int(input()) for _ in range(n)]
    s = sum(a[0:k])
    ss = [s]
    for i in range(k, n):
        s = s + a[i] - a[i-k]
        ss.append(s)
    print(max(ss))

Submission status: Accepted

Solution code:
while True :
    n,k=map(int,input().split())
    if n==0 : break
    x=[int(input()) for i in range(n)]
    ans=0
    xsum=sum(x[:k])
    for i in range (n-k):
        ans=max(ans,xsum)
        xsum=xsum - x[i] + x[i+k]
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    else:
        a=[]
        s=0
        t=[]
        u=0
        for i in range(n):
            a.append(int(input()))
        for j in range(k):
            s+=a[j]
        t.append(s)
        for l in range(k,n):
            s=t[u]-a[l-k]+a[l]
            t.append(s)
            u+=1
        print(max(t))

Submission status: Accepted

Solution code:
while True:
    a = []
    b = [0]
    c = []
    n, k = map(int, input().split())
    if n == k == 0:
        break

    for i in range(n):
        x = int(input())
        a.append(x)
        b.append(b[i] + x)

    for i in range(n - k + 1):
        c.append(b[k + i] - b[i])

    print(max(c))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n==k==0:
        break
    a =[]
    for i in range(n):
        a.append(int(input()))
    ans = sum(a[0:k:])
    tmp = ans
    for i in range(n-k):
        tmp += a[k+i]
        tmp -= a[i]
        if ans < tmp:
            ans = tmp
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n, k = [int(i) for i in input().split(" ")]
    if n == 0 and k == 0:
        break
    a = [int(input()) for _ in range(n)]

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

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

    print(m)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[]
    for i in range (n):
        a.append(int(input()))
        c=0
    for i in range(k):
        c+=a[i]
        b=c
    for i in range(k,n):
        c+=a[i]
        c-=a[i - k]
        b=max(b,c)
    print(b)

Submission status: Accepted

Solution code:
x=[]
y=[]
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:break
    else:
        x=[int(input()) for i in range(n)]
        if len(x)<k:
            pass
        else:
            s=sum(x[0:k])
            y.append(s)
            for i in range(0,n-k):
                s=s-x[i]+x[i+k]
                y.append(s)
            print(max(y))

Submission status: Accepted

Solution code:
l = []
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    for i in range(n):
        l.append(int(input()))
    n_sum1 = 0
    n_sum2 = 0
    n_max = 0
    for i in range(k):
        n_sum1 += l[i]
    for i in range(n-k):
        n_sum2 =n_sum1 - l[i] +l[i+k]
        if n_sum2 > n_max:
            n_max = n_sum2
        n_sum1 = n_sum2
    print(n_max)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    sn=[]
    for i in range(n):
        sn.append(int(input()))
    c=[]
    for j in range(0,n-k+1):
        if j==0:
            fsum = sum(sn[0:k])
        else:
            fsum = fsum + sn[j+k-1] - sn[j-1]
        c.append(fsum)
    print(max(c))

Submission status: Accepted

Solution code:
while True :
    n, k = map(int, input().split())
    
    if n == 0 and k == 0:
        break
    else:
        a=[int(input()) for i in range(n)]
        b = sum(a[0:k])
        c = []
        for i in range(n-k):
            b += a[k+i] - a[i]
            c.append(b)
        print(max(c))

Submission status: Accepted

Solution code:
s=0
while True:
    n,k = map(int, input().split())
    list = [int(input()) for i in range(n)]
    if n==0 and k==0:
        break
    a=sum(list[0:k])
    b=[a]
    for i in range(n-k):
        a += list[i+k]-list[i]
        b.append(a)
    print(max(b))

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==m==0:break
    alist = []
    for i in range (n):
        a=int(input())
        alist.append(a)
    s = sum(alist[0:m])   #a[i:j]→[a[i], a[i+1], a[i+2], ..., a[j-1]]
    max = s
    for i in range(m, n):
        s = s + alist[i] - alist[i - m]
        if s > max:
            max = s
    print(max)

Submission status: Accepted

Solution code:
from queue import deque

while True:
    n, k = map(int, input().split())
    if not n:
        break
    q = deque(int(input()) for _ in range(k))
    ans = cur = sum(q)
    for _ in range(n - k):
        new = int(input())
        q.append(new)
        old = q.popleft()
        cur += new - old
        ans = ans if ans > cur else cur
    print(ans)

Submission status: Accepted

Solution code:
import queue
while 1:
    n,k=map(int,input().split())
    if n == 0:break
    r=queue.deque(int(input()) for _ in range(k))
    s=t=sum(r)
    for i in range(n-k):
        u=r.popleft()
        v=int(input())
        r.append(v)
        t+=v-u
        s=max(t,s)
    print(s)

Submission status: Accepted

Solution code:
while 1:
  n,k = map(int,input().split())
  if n == k == 0:
    break
  a = []
  for i in range(n):
    a.append(int(input()))
    c = 0
  for i in range(k):
    c += a[i]
    b = c
  for i in range(k, n):
    c += a[i]
    c -= a[i - k]
    b = max(b,c)
  print(b)

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    c = 0
    for i in range(k):
        c += a[i]
        b = c
    for i in range(k, n):
        c += a[i]
        c -= a[i - k]
        b = max(b,c)
    print(b)

Submission status: Accepted

Solution code:
#aとbが0のとき処理を終わる
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:break

    #カラリストの作成と変数のリセット
    line = []
    kei = []
    i = 0
    
    #標準入力
    for _ in range(a):line.append(int(input()))
    
    #しゃくとり法の最初の数を変数に代入する
    for j in range(0,b):i += line[j]
    
    #しゃくとり法の更新
    for l in range(b,a):
        i += line[l] - line[l - b]
        kei.append(i)
        
    #出力
    print(max(kei))

Submission status: Accepted

Solution code:

for x in range (5):
    a,k = map(int, input().strip().split())
    if a==k==0 : break
    lst=[int(input()) for i in range(a)]
    s = sum(lst[0:k])
    mx = s
    for i in range (k,a):
        s = s + lst[i] -lst[i-k]
        if s > mx :
            mx = s
            
        
    print(mx)

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if (n,k) == (0,0):
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
        c = 0
    for j in range(k):
        c += a[j]
        b = c
    for h in range(k,n):
        c += a[h]
        c -= a[h - k]
        b = max(b,c)
    print(b)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while 1:
  n,k = map(int,input().split())
  if n == k == 0:
    break
  a = []
  for i in range(n):
    a.append(int(input()))
    c = 0
  for i in range(k):
    c += a[i]
    b = c
  for i in range(k, n):
    c += a[i]
    c -= a[i - k]
    b = max(b,c)
  print(b)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
        count = 0
    for i in range(k):
        count += a[i]
        ans = count
    for i in range(k, n):
        count += a[i]
        count -= a[i - k]
        ans = max(ans, count)
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    r=[]
    for I in range(n):
        x=int(input())
        r.append(x)
    s=[]
    i=0
    MAX=sum(r[0:k])
    PRE=MAX
    for J in range(n-k):
        a=r[i]
        b=r[i+k]
        PRE=PRE-a+b
        if PRE>MAX:
            MAX=PRE
        else:
            pass
        i+=1
    print(MAX)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")

# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_B
import sys
sys.setrecursionlimit(1000000)
INF = float("inf")

while True:
    N,K = map(int,sys.stdin.readline().split())
    if N==0 and K==0:
        exit()
    a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param

    com = [0]*(N+1)
    for i in range(N):
        com[i+1]=com[i]+a[i]

    ret = -INF
    for i in range(N-K):
        ret = max(ret,com[i+K]-com[i])
    print(ret)

Submission status: Accepted

Solution code:
while True:
    l,m=map(int,input().split())
    if l==0 and m==0:
        break
    a=[int(input()) for i in range(l)]
    b=sum(a[0:m])
    c=[b]
    for i in range(l-m):
        b+=a[i+m]-a[i]
        c.append(b)
    print(max(c))

Submission status: Accepted

Solution code:
#48 最大の和
while True:
        n, k = map(int, input().split())
        if n == k == 0:
                break
        
        a = [int(input()) for i in range(n)]
        s = sum(a[0:k])                         #リストaの0からkまでの和をsとする
        max = s                                 #maxにsを代入する
        for i in range(k,n):                    
                s = s + a[i] - a[i-k]           
                if s > max:                     #sがmaxより大きければmaxにsを代入する
                        max = s
        print(max)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if (n,k)==(0,0):
        break
    lst=[int(input()) for i in range(n)]
    a=[]
    c=0
    for i in range(k):
        c+=lst[i]
    a.append(c)
    for j in range(n-k):
        c+=lst[k+j]
        c-=lst[j]
        a.append(c)
    print(max(a))

Submission status: Accepted

Solution code:
def solve(n,k,a):
    S=[0]*(n+1)
    S[0]=a[0]
    for i in range(0,n):
        S[i+1]=S[i]+a[i]
    ans=-S[k-1]
    for i in range(0,n-k+1):
        if ans<S[i+k]-S[i]:
            ans=S[i+k]-S[i]
    return ans
n,k=map(int,input().split())
while n>0:
    a=[int(input()) for _ in range(n)]
    ans=solve(n,k,a)
    print(ans) 
    n,k=map(int,input().split())

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    s=sum(a[0:k])
    max=s
    for i in range(k,n):
        s=int(s+a[i]-a[i-k])
        if max<s:
            max=s
    print(max)

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split())
    if n==0 and k==0:
        break
    a = []
    for i in range(1,n+1):
        a.append(int(input()))
        i += 1
    max = sum(a[0:k])
    b = sum(a[0:k])
    for j in range(0,n-k):
        c = b-a[j]+a[j+k]
        b = c
        if c > max:
            max = c
    print(max)