백준 [ALGORITHM] - 수들의 합2 (2003)

2024. 12. 5. 12:16코딩/백준 [ALGORITHM]

반응형
N, M = map(int, input().split())
A = list(map(int, input().split()))

start = 0
end = 0
current_sum = 0
count = 0

while end <= N:
    if current_sum < M:
        if end < N:
            current_sum += A[end]
        end += 1
    elif current_sum > M:
        current_sum -= A[start]
        start += 1
    else:
        count += 1
        current_sum -= A[start]
        start += 1
print(count)
반응형