BOJ - 2559 - 수열

Updated:

import sys

def solution():
    N, K = map(int, sys.stdin.readline().split())
    item = list(map(int, sys.stdin.readline().split()))
    idx = 0
    temp = sum(item[0:K])
    maxSum = temp

    if K == 1:
        print(max(item))
    else:
        while True:
            temp -= item[idx]
            if idx + K >= N: break

            temp += item[idx + K]

            if maxSum < temp: maxSum = temp

            idx += 1

        print(maxSum)
solution()

https://www.acmicpc.net/problem/2559

Categories:

Updated:

Leave a comment