import sys
input=sys.stdin.readline
n,k=map(int,input().split())
nums=list(map(int,input().split()))
n=len(nums)
l=0
total=0
ans=0
for r in range(n):
total+=nums[r]
while l<n and total-nums[l]>=k:
total-=nums[l]
l+=1
if total>=k:
ans+=l+1
print(ans)
不难看出,枚举右
时间复杂度O(n)

京公网安备 11010502036488号