Skip to content

Commit

Permalink
solve : 1806 부분합
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 16, 2024
1 parent f1384ac commit 21df004
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions python/boj_1806.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

input = sys.stdin.readline


def solution(n, s, data):
left, right = 0, 0
prefix_sum = 0
answer = sys.maxsize

while True:
if prefix_sum >= s:
answer = min(answer, right - left)
prefix_sum -= data[left]
left += 1
elif right == n:
break
else:
prefix_sum += data[right]
right += 1

if answer == sys.maxsize:
return 0
else:
return answer


def display_result(answer):
print(answer)


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


main()

0 comments on commit 21df004

Please sign in to comment.