본문 바로가기
백준알고리즘/투포인터

(Python/🥈3)백준알고리즘 2559번: 수열

by windy7271 2023. 3. 22.
728x90
반응형

문제출처:https://www.acmicpc.net/problem/2559

풀이:

import sys

sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r')

N, K = map(int,input().split(" "))
nums = list(map(int,input().split(" ")))

now = 0
for i in range(K):
    now += nums[i]
maxn = now

for i in range(K,N):
    now += nums[i]
    now -= nums[i-K]
    maxn = max(maxn,now)

print(maxn)
반응형

댓글