题解 | #未排序数组中累加和为给定值的最长子数组长度#
未排序数组中累加和为给定值的最长子数组长度
https://www.nowcoder.com/practice/36fb0fd3c656480c92b569258a1223d5
N,k = map(int,input().split())
arr = list(map(int,input().split()))
sum = 0
length = 0
tmp_dict = {0:-1}
for i in range(len(arr)):
sum += arr[i]
if sum not in tmp_dict:
tmp_dict[sum] = i
if sum - k in tmp_dict:
length = max(length,i-tmp_dict[sum - k])
print(length)
