문제

2003번: 수들의 합 2

풀이

구현

n, m = map(int, input().split())
num = list(map(int, input().split()))

count = 0
start = 0
end = 0
summ = 0
while (1):
	if summ < m:
		if end >= n:
			break
		summ += num[end]
		end += 1
	elif summ >= m:
		summ -= num[start]
		start += 1
	if summ == m:
		count += 1
print(count)
n, m = map(int, input().split())
num = list(map(int, input().split()))

count = 0
start = 0
end = 0
summ = num[end]
while (1):
	if summ == m:
		count += 1
	if summ < m:
		end += 1
		if end >= n:
			break
		summ += num[end]
	elif summ >= m:
		summ -= num[start]
		start += 1
print(count)