practivceAlgorithm/백준

[백준][Python] 2435 기상청 인턴 신현수

findTheValue 2021. 8. 26. 10:52

슬라이딩 윈도우

 

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
arr = list(map(int, input().split()))
left = 0
prefix_sum = 0
answer = -float('inf')
for right in range(N):
    prefix_sum += arr[right]
    while right-left+1 >= M:
        answer = max(answer, prefix_sum)
        prefix_sum -= arr[left]
        left += 1
print(answer)