fork download
  1. def main(arr,k):
  2. cnt=0
  3. s=0
  4. n=len(arr)
  5. i=0
  6. for j in range(n):
  7. ele=arr[j]
  8. s+=ele
  9.  
  10. while s>k and i<=j:
  11. s-=arr[i]
  12. i+=1
  13.  
  14. cnt+=(j-i+1)
  15.  
  16. return cnt
  17.  
  18. print(main([2, 5, 6],10))
Success #stdin #stdout 0.07s 7996KB
stdin
Standard input is empty
stdout
4