BOJ - 2003 - 수들의 합 2

Updated:

import sys

def solution():
    N, M = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    left = 0
    right = 0
    ret = 0
    s = 0

    while True:
        if s >= M:
            s -= A[left]
            left += 1
        else:
            if right == N: break

            s += A[right]
            right += 1
        if s == M:
            ret += 1
    print(ret)

solution()

https://www.acmicpc.net/problem/수들의 합 2

Categories:

Updated:

Leave a comment