Skip to content

Commit 5e8f7a0

Browse files
committed
[BOJ] #2559. 수열 / 실버3 / 29분(성공)
1 parent 975568f commit 5e8f7a0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
input = sys.stdin.readline
3+
# N: 온도를 측정한 전체 날짜 수 / K: 연속적인 날짜의 수
4+
N, K = map(int, input().strip().split())
5+
temp = list(map(int, input().strip().split())) # 온도 리스트
6+
prefix_sum = [0] * (N+1) # 누적합 리스트
7+
section = N - K + 1 # 구간합 리스트를 초기화하기 위한 크기
8+
range_sum = [0] * section # 구간합 리스트
9+
10+
# 누적합 구하기
11+
for i in range(len(temp)):
12+
prefix_sum[i+1] = temp[i] + prefix_sum[i]
13+
14+
# 구간합 구하기
15+
for i in range(K, section+K):
16+
range_sum[i-K] = prefix_sum[i] - prefix_sum[i-K]
17+
18+
print(max(range_sum)) # K일의 온도의 합이 최대가 되는 값

0 commit comments

Comments
 (0)