Baekjoon #2559

Baekjoon #2559

1개의 풀이 · Python

문제 원문 보기 ↗

SOLUTION INFO

Python · main.py

main.py
import sys

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

N, K = map(int, input().split())
arr = list(map(int, input().split()))
total = 0
MAX = -1e9
s, e = 0, K-1
if K == 1:
    print(max(arr))
else:
    total = sum(arr[:K])
    while True:
        MAX = max(MAX, total)
        total -= arr[s]
        s += 1
        e += 1
        if e == N:
            break
        total += arr[e]
    print(MAX)

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.