https://www.acmicpc.net/problem/2003
2003번: 수들의 합 2
첫째 줄에 N(1 ≤ N ≤ 10,000), M(1 ≤ M ≤ 300,000,000)이 주어진다. 다음 줄에는 A[1], A[2], …, A[N]이 공백으로 분리되어 주어진다. 각각의 A[x]는 30,000을 넘지 않는 자연수이다.
www.acmicpc.net
N, M = map(int, input().split())
nums = list(map(int, input().split()))
left, right = 0, 1
cnt = 0
while right<=N and left<=right:
sum_nums = nums[left:right]
total = sum(sum_nums)
if total == M:
cnt += 1
right += 1
elif total < M:
right += 1
else:
left += 1
print(cnt)
'Koala - 14기 > 코딩테스트 준비 스터디' 카테고리의 다른 글
[백준/C++] 11576번 Base Conversion (0) | 2024.04.06 |
---|---|
[백준/Python3] 11659번 : 구간 합 구하기4 (0) | 2024.04.06 |
[백준/C++] 3190번 뱀 (0) | 2024.04.01 |
[백준/Python] 2230번 수고르기 (0) | 2024.03.31 |
[백준/Python] 2470번 두 용액 (0) | 2024.03.31 |