Skip to content

Commit 6d42c0b

Browse files
committed
[BOJ]부분합/ Silver /40min
https://www.acmicpc.net/problem/1806
1 parent 1dfb830 commit 6d42c0b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Hongjoo/백준/부분합.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
https://www.acmicpc.net/problem/1806
3+
"""
4+
import sys
5+
N ,S = map(int, sys.stdin.readline().split())
6+
arr = list(map(int, input().split()))
7+
8+
start , end = 0, 0
9+
min_length = 100000
10+
partial_sum = arr[0]
11+
while start <= end :
12+
if partial_sum >= S : # S보다 큰 부분합인 경우
13+
min_length = min(min_length , end - start +1 ) # 최소 길이 업데이트 확인
14+
partial_sum -= arr[start] # start +1 이동
15+
start += 1
16+
else : #partial_sum < S :
17+
end += 1
18+
if end < N :
19+
partial_sum += arr[end]
20+
else : # 수열 끝 -> 조건 충족 x
21+
break
22+
23+
24+
if min_length == 100000 :
25+
print(0)
26+
else :
27+
print(min_length)

0 commit comments

Comments
 (0)