Skip to content

Baekjoon 2003

1. Problem

문제 확인하기

2. Solution

import sys

n, m = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))

cnt = 0
low, high = 0, 1
tmp = arr[low]
while low < n:
    if tmp == m:
        cnt += 1
        tmp -= arr[low]
        low += 1
    
    if high == n and tmp < m:
        break
    elif tmp < m:
        tmp += arr[high]
        high += 1
    elif tmp > m:
        tmp -= arr[low]
        low += 1

print(cnt)