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
    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:
def resolve():
    N, M = [int(i) for i in input().split()]
    while N + M != 0:
        A = [int(input()) for _ in range(N)]
        preSum = [0] * (N + 1)
        for i in range(N):
            preSum[i + 1] = preSum[i] + A[i]
        maxA = -10000 * M - 1
        for i in range(M, N):
            maxA = max(maxA, preSum[i] - preSum[i - M])
        print(maxA)
        N, M = [int(i) for i in input().split()]


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
A = True
while A:
  n, k = map(int,input().split())
  if n == 0 and k == 0:
    break

  S = [-1 for _ in range(n)]
  for i in range(n):
    temp = int(input())
    if i == 0:
      S[i] = temp
    else:
      S[i] = S[i-1]+temp

  ans = S[k-1]
  for i in range(n-k): #0かあn-k-1まで。
    temp = S[i+k]-S[i]
    ans = max(ans,temp)
  print(ans)

Submission status: Accepted

Solution code:
while 1:
    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])
    M = s
    
    for i in range(k, n):
        s = s + a[i] - a[i - k]
        if s > M:
            M = s
            
    print(M)

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

Submission status: Accepted

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

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])
    ma=s
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        if s>ma:
            ma=s
    print(ma)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# 48

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

Submission status: Accepted

Solution code:
#0516
while True:
    x = 0
    a = []
    S = []
    s = 0
    cnt = 0
    n , k = map(int,input().split())
    if n == 0 and k == 0:
        break
    for i in range(n):
        a.append(int(input()))

    S.append(sum(a[0:k]))
    
    for j in range(k,n):
        s = S[cnt] - a[j - k] + a[j]
        S.append(s)
        cnt += 1
    
    print(max(S))

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=0
	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: break
    a = [int(input()) for _ in range(n)]

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

    ans = -10**16
    for i in range(n-k+1):
        ans = max(ans, cs[i+k]-cs[i])

    print(ans)

Submission status: Accepted

Solution code:
import queue
while True:
    n,k=map(int,input().split())
    if n==0:break
    a=queue.deque(int(input()) for _ in range(k))
    m=b=sum(a)
    for i in range(n-k):
        c=a.popleft()
        d=int(input())
        a.append(d)
        b+=d-c
        m=max(b,m)        
    print(m)

Submission status: Accepted

Solution code:
import sys
def mips():
    return map(int,input().split())
def ii():
    return int(input())
#AOJ_maximum sum
def procedure():
    N,K = mips()
    if N == 0:
        sys.exit(0)
    A = []
    res = -(10**100)
    for _ in range(N):
        a = ii()
        A.append(a)
    S = [0]
    for i in range(N):
        s = S[i] + A[i]
        S.append(s)
    for i in range(N-K):
        res = max(res,S[i+K]-S[i])
    print(res)
while True:
    procedure()

Submission status: Accepted

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

Submission status: Accepted

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

    s = [0 for i in range(n+1)]
    # 累積和配列の生成
    for i in range(n):
        s[i+1] = s[i] + a[i]

    ans = -float("inf")
    for i in range(n-k):
        ans = max(ans, s[i+k] - 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 i in range(n)]
    b = 0
    s = [0]*(n+1)
    
    for i in range(n):
        s[i+1]=s[i]+a[i]
        
    for i in range(n-k+1):
        tmp = s[k+i]-s[i]
        if tmp>b:
            b = tmp

    print(b)

Submission status: Accepted

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

    if n==k==0:
        break
    x=[int(input())]
    
    for i in range(n-1):
        y=int(input())
        x.append(x[i]+y)
    
    maxx=x[0]
    
    for i in range(n-k):
        maxx=max(maxx,x[i+k]-x[i])
    
    print(maxx)

Submission status: Accepted

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

try:
   while True:
      n, k = map(int, input().split())
      if n + k == 0:
         break
      
      l = []
      for i in range(n):
         l.append(int(input()))

      s1 = 0
      for i in range(k):
         s1 += l[i]
      
      ma = 0
      s2 = 0
      for j in range(n - k):
         s2 = s1 - l[j] + l[j + k]
         if s2 > ma:
            ma = s2
         s1 = s2
      print(ma)

except EOFError:
   pass

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[0]*n
    for i in range(n):
        a[i]=int(input())
    s=[0]*(n+1)
    for i in range(n):
        s[i+1]=s[i]+a[i]
    ans=int()
    for i in range(n-k+1):
        ans=max(ans,s[k+i]-s[i])
    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 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:
def calc(n, k):
	a = [int(input()) for _ in range(n)]
	s = [0] * (n + 1)
	for i in range(n):
		s[i + 1] = s[i] + a[i]
	ans = float('-inf')
	for i in range(n-k+1):
		ans = max(ans, s[k+i] - s[i])
	print(ans)

def resolve():
	while True:
		n, k = map(int, input().split())
		if n == 0 and k == 0:
			return
		calc(n, k)
resolve()

Submission status: Accepted

Solution code:
def solve():
    while 1:
        n, k = [int(_) for _ in input().split()]
        if n == 0: return

        A = [int(input()) for _ in range(n)]
        s = [0] * (len(A) + 1)
        for i in range(n):
            s[i + 1] = s[i] + A[i]

        ans = -1
        for l in range(n):
            r = l + k
            if r > n: break
            ans = max(ans, s[r] - s[l])
        print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    while True:
        n, m = map(int, input().split())
        if [n, m] == [0, 0]:
            break
        else:
            A = [int(input()) for i in range(n)]
            B = [0] + A
            # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
            B = list(accumulate(B))

            val = max([B[i + m] - B[i] for i in range(n - m + 1)])
            print(val)

resolve()

Submission status: Accepted

Solution code:
import itertools
while True:
    N, K = map(int, input().split())
    if N==K==0:
        break
    S = [int(input()) for _ in range(N)]
    
    Scum = [0] + list(itertools.accumulate(S))
    reg = -10**9
    for i in range(N-K+1):
        partial_sum = Scum[i+K] - Scum[i]
        reg = max(reg, partial_sum)
    print(reg)

Submission status: Accepted

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

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

    ans = -10*18
    for i in range(n-k+1):
        if s[i+k] - s[i] > ans:
            ans = s[i+k] - s[i]

    print(ans)

Submission status: Accepted

Solution code:
while True:
    n,k=map(int,input().split())
    a=[]
    if n==0 and k==0:
        break
    for _ in range(n):
        a.append(int(input()))
    
    s=[0 for _ in range(n+1)]
    for i in range(n):
        s[i+1]=s[i]+a[i]
    ans=0
    for i in range(n-k):
        ans=max(ans,s[i+k]-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 = [0]*n
    for i in range(n):
        a[i] = int(input())

    s = [0]*(n+1)
    for i in range(n):
        s[i+1] = s[i] + a[i]
    
    ans = -float('inf')
    for i in range(n-k+1):
        ans = max(ans,s[k+i]-s[i])
    print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

def main():
    while True:
        n, k = map(int, readline().split())
        if n == 0 and k == 0:
            return
        a = []
        for _ in range(n):
            a.append(int(readline()))

        base = sum(a[:k])
        subsum = [base]
        for i in range(k,n):
            base += a[i]
            base -= a[i-k]
            subsum.append(base)

        print(max(subsum))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
for i in range(5):
    n,k = map(int,input().split())
    if n == 0 and k == 0:
        break
    else:
        ruiseki = [0]*(n+1)
        total = 0
        maximum = -(10**9+7)
        for i in range(n):
            p = int(input())
            total += p
            ruiseki[i+1] = total
        for i in range(n-k+1):
            if ruiseki[i+k]-ruiseki[i]>maximum:
                maximum = ruiseki[i+k]-ruiseki[i]
        print(maximum)

Submission status: Accepted

Solution code:
from itertools import accumulate

while True:
  n, k = map(int, input().split())
  if n == 0 and k == 0:
    break
  A = [int(input()) for _ in range(n)]
  
  S =[0] + list(accumulate(A))
  d = [S[i]-S[i-k] for i in range(k, n+1)]
  print(max(d))

Submission status: Accepted

Solution code:
while True:
    n,k = map(int,input().split(" "))
    if n == 0 and k == 0:
        break
    else:
        nums = [int(input()) for _ in range(n)]
        ruiseki = [0] * (n + 1)
        for i,num in enumerate(nums):
            ruiseki[i + 1] = ruiseki[i]  + num
        # print(ruiseki)
        ans = - (10 ** 15)
        for left in range(n - k):
            ans = max(ans, ruiseki[left + k] - ruiseki[left])
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

while True:
    N, K = map(int, input().split())
    if N == 0:
        break
    A = [int(input()) for _ in range(N)]

    S = list(accumulate([0] + A))
    ans = max(S[i] - S[i-K] for i in range(K, len(S)))
    print(ans)

Submission status: Accepted

Solution code:
max = -10**9
for i in range(5):
  n,k = map(int,input().split())
  if n==0 and k == 0:
    break
  else:
    b = []*n
    sum = 0
    max = -10**9
    for i in range(n):
      a = int(input())
      b.append(sum+a)
      sum += a
    for j in range(len(b)-k):
      if max<b[j+k]-b[j]:
        max = b[j+k]-b[j]
    print(max)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    while True:
        n, k = list(map(int, input().strip().split()))
        if n == 0 and k == 0:
            return
        v = [0] * n
        a = [0] * (n+1)
        for i in range(n):
            v[i] = int(input().strip())
        for i in range(n):
            a[i+1] = v[i] + a[i]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
while True:
    n, k = [int(x) for x in input().split()]
    if n == 0 and k == 0:
        break
    L = []
    for _ in range(n):
        L.append(int(input()))

    M = list(accumulate(L))
    S = []
    S.append(M[k-1])

    for i in range(k,n):
        S.append(M[i] - M[i-k])
    print(max(S))

Submission status: Accepted

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

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def solve():
    n, k = read_h()
    arr = read_v(n)

    cumul = [sum(arr[:i]) for i in range(len(arr) + 1)]
    #  print(cumul)

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

    print(ans)


def main():
    while True:
        n, k = read_h()
        if (n, k) == (0, 0):
            break

        arr = read_v(n)

        cumul = [0]
        for i in range(n):
            cumul.append(cumul[i] + arr[i])

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

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def shak(n,k):

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


	l,r=0,k
	res=0
	cnt=sum(a[l:r])
	while r<n:
		res=max(res,cnt)

		cnt=cnt+a[r]-a[l]
		r+=1
		l+=1
	print(res)

for i in range(5):
	n,k=map(int,input().split())
	if n==k==0:exit()
	shak(n,k)

Submission status: Accepted

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

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 = [0] * (n+1)
    
    for i in range(n):
        s[i+1] = s[i] + a[i]
    
    ans = -float('inf')
    for i in range(n-k+1):
        tmp = s[k+i] - s[i]
        if tmp > ans:
            ans = tmp
    
    print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N, K = map(int, input().split())
    if N == 0:
        exit()
    A = [int(input()) for _ in range(N)]
    S = sum(A[:K])

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


def solve2():
    N, K = map(int, input().split())
    if N == 0:
        exit()
    else:
        A = [int(input()) for _ in range(N)]
        A = [0]+list(accumulate(A))
        ans = max([A[i+K]-A[i] for i in range(N-K)])
        print(ans)


while True:
    solve2()

Submission status: Runtime Error

Solution code:
from itertools import accumulate

# 区間[N-k, N) の総和の最大値

while True:
  n, k = map(int, input().split(" "))
  if n == 0:
    break
  a_n = [int(input()) for _ in range(n)]
  _ = input()

  a_n = list(accumulate(a_n))
  # print(a_n)

  result = -99999999999999

  for i in range(n-k):
    val = a_n[k+i] - a_n[i]
    if result < val:
      result = val


  print(result)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

# 区間[N-k, N) の総和の最大値

while True:
  n, k = map(int, input().split())
  if n == 0:
    break
  a_n = [int(input()) for _ in range(n)]
  _ = input()

  a_n = list(accumulate(a_n))
  # print(a_n)

  result = -99999999999999

  for i in range(n-k):
    val = a_n[k+i] - a_n[i]
    if result < val:
      result = val


  print(result)

Submission status: Runtime Error

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

L=[]
for i in range(n):
    if(i == 0):
        L.append(0)
        L.append(l[i])
    else:
        L.append(L[i]+l[i])

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

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n, k = readi(2)
    a = readi(n)
    tmp = sum(a[:k])
    ans = tmp
    dbg(tmp=tmp)
    for i in range(k, len(a)):
        tmp += a[i] - a[i - k]
        ans = max(ans, tmp)
        dbg(tmp=tmp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def func(n,k):
    A = []
    ans = 0
    for i in range(n):
        A.append(int(input()))
    for i in range(k-1):
        SUM += A[i]
    for i in range(k,len(a)):
        ans = max(ans,SUM+a[i]-a[i-k])
    print(ans)

for i in range(100):
    n,k = [int(s) for s in input().split()]
    if n == 0 and k ==0:
        break
    else:
        func(n,k)

Submission status: Runtime Error

Solution code:
def func(n,k):
    A = []
    ans = 0
    SUM = 0
    for i in range(n):
        A.append(int(input()))
    for i in range(k-1):
        SUM += A[i]
    for i in range(k,len(a)):
        ans = max(ans,SUM+a[i]-a[i-k])
    print(ans)

for i in range(100):
    n,k = [int(s) for s in input().split()]
    if n == 0 and k ==0:
        break
    else:
        func(n,k)

Submission status: Runtime Error

Solution code:
def func(n,k):
    SUM = 0
    A = [int(input()) for _ in range(n)]
    for i in range(k-1):
        SUM += A[i]
    ans = SUM
    for i in range(k,len(A)):
        ans = max(ans,SUM+A[i]-A[i-k])
    print(ans)

for _ in range(10)
    n,k = [int(s) for s in input().split()]
    if n == 0 and k ==0:
        break
    else:
        func(n,k)

Submission status: Runtime Error

Solution code:
def func(n,k):
    SUM = 0
    ans = 0
    A = [int(input()) for _ in range(n)]
    for i in range(k-1):
        SUM += A[i]
    for i in range(k,len(A)):
        ans = max(ans,SUM+A[i]-A[i-k])
        SUM = SUM+A[i]-A[i-k]
    print(ans)

for _ in range(10)
    n,k = [int(s) for s in input().split()]
    if n == 0 and k ==0:
        break
    else:
        func(n,k)

Submission status: Runtime Error

Solution code:
 while 1:                                    
     n, k = (int(x) for x in input().split())
     if n == 0:                              
         break                               
     max_num = -30001                        
     queue = list()                          
     for _ in range(k):                      
         queue.append(int(input()))          
         max_num = sum(queue)                
     queue.pop(0)                            
     for _ in range(n - k):                  
         queue.append(int(input()))          
         max_num = max(sum(queue), max_num)  
         queue.pop(0)                        
     print(max_num)

Submission status: Runtime Error

Solution code:
while 1:
    n,k = [int(i) for i in input().split()]
    if not n and k:
        break
    a = [int(input()) for i in range(n)]
    b = [0]*len(a)

    for i in range(n):
        b[i] = b[i-1] + a[i]
    b = b + [0]

    c = [b[i + k - 1] - b[i - 1] for i in range(n - k + 1)]

    print(max(c))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
int main(){
  int i,n,k,s;
  while (1){
    int ma=0;
    scanf("%d %d",&n,&k);
    if (n==0 && k==0)break;
    int a[n];
    for (i=0;i<n;i++)
      scanf("%d",&a[i]);
    for (i=0;i<n-2;i++){
      s=a[i]+a[i+1]+a[i+2];
      if (s>ma) ma=s;
    }
    printf("%d\n",ma);
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
L = [x for x in open('input.txt', 'r')]

n = int(L[0].split(' ')[0])
k = int(L[0].split(' ')[1])

L = map(int, L[1:])

max = 0
for x in range(1,n-(k-1)):
        if max < sum(L[x:x+k]):
                max = sum(L[x:x+3])

print max

Submission status: Runtime Error

Solution code:
import sys

f = open('input.txt','w')

while 1:
        line = raw_input()
        if line == '0 0':
                break
        f.write(line)
        f.write('\n')

f.close()

L = [x for x in open('input.txt', 'r') if x != "0 0"]

n = int(L[0].split(' ')[0])
k = int(L[0].split(' ')[1])

L = map(int, L[1:])

max = 0
for x in range(1,n-(k-1)):
        if max < sum(L[x:x+k]):
                max = sum(L[x:x+3])

print max

Submission status: Runtime Error

Solution code:
import sys

f = open('input.txt','w')

while 1:
        line = raw_input()
        if line == '0 0':
                f.write(line)
                break
        f.write(line)
        f.write('\n')

f.close()

L = [x for x in open('input.txt', 'r')]

L[0].split(' ')

n = int(L[0].split(' ')[0])
k = int(L[0].split(' ')[1])

L = L[:-1]
L = map(int, L[1:])

max = 0
for x in range(1,n-(k-1)):
        if max < sum(L[x:x+k]):
                max = sum(L[x:x+3])

print max

Submission status: Runtime Error

Solution code:
f = open('input.txt','w')

while 1:
        line = raw_input()
        if line == '0 0':
                f.write(line)
                break
        f.write(line)
        f.write('\n')

f.close()

L = [x for x in open('input.txt', 'r')]

L[0].split(' ')

n = int(L[0].split(' ')[0])
k = int(L[0].split(' ')[1])

L = L[:-1]
L = map(int, L[1:])

max = 0
for x in range(1,n-(k-1)):
        if max < sum(L[x:x+k]):
                max = sum(L[x:x+3])

print max