from itertools import accumulate n,k=map(int,input().split()) number=list(map(int,input().split())) for i in range(n): number[i]-=k number1=list(accumulate(number,initial=0)) dict1={} count=-1 for index,value in enumerate(number1): if value not in dict1: dict1[value]=index else: count=max(count,index-dict1[value]) print(count)
先利用accumulate算出前缀和(自己算也行),然后用enumerate函数来枚举数和数的位置,逐步更新区间最大值