Skip to content

Commit

Permalink
solve : 21021 블로그
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 19, 2024
1 parent 5db3a9d commit c118df3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions python/boj_21921.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

input = sys.stdin.readline


def solution(n, m, data):
if max(data) == 0:
return "SAD"

prefix_sum = [0]
for i in range(n):
prefix_sum.append(prefix_sum[i] + data[i])

max_value = -1
count = 0
for i in range(n - m + 1):
visited = prefix_sum[i+m] - prefix_sum[i]
if visited > max_value:
count = 1
max_value = visited
elif visited == max_value:
count += 1

return max_value, count


def display_result(answer):
[print(e) for e in answer]


def main():
n, m = map(int, input().split())
data = list(map(int, input().split()))
answer = solution(n, m, data)
display_result(answer)


main()

0 comments on commit c118df3

Please sign in to comment.