We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1dfb830 commit 6d42c0bCopy full SHA for 6d42c0b
Hongjoo/백준/부분합.py
@@ -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