m存储前i项和对应下标,a存储前i项和,ans最大长,即求第i项时m[a-k]是否存在

def solve(l, n, k):
    m = {0:-1}
    a = ans = 0
    for i in range(n):
        a += l[i]
        if a not in m.keys():
            m[a] = i
        if a - k in m.keys():
            ans = max(ans, i - m[a-k])
    return ans

while True:
    try:
        n, k = map(int, input().split())
        l = list(map(int, input().split()))
        print(solve(l, n, k))
    except EOFError:
        break