Skip to content

Commit 4313521

Browse files
committed
[백준] 부분 합 / 골드 4 / 40분
https://www.acmicpc.net/problem/1806
1 parent 36e44af commit 4313521

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
3+
# 입력 처리
4+
N, S = map(int, sys.stdin.readline().split())
5+
arr = list(map(int, sys.stdin.readline().split()))
6+
7+
# 초기화
8+
ans = float('inf')
9+
start, end = 0, 0
10+
current_sum = 0
11+
12+
# 투 포인터로 부분합 찾기
13+
while end < N:
14+
current_sum += arr[end]
15+
end += 1
16+
17+
# 현재 합이 S 이상일 경우
18+
while current_sum >= S:
19+
ans = min(ans, end - start)
20+
current_sum -= arr[start]
21+
start += 1
22+
23+
24+
print(0 if ans == float('inf') else ans)

0 commit comments

Comments
 (0)