fork download
  1. n,m=map(int,input().strip().split())
  2. a=list(map(int,input().strip().split()))
  3.  
  4. #4 5
  5. #3 1 2 1
  6. #find max number of books can read
  7.  
  8. ans=0
  9. l=0
  10. sum=0
  11.  
  12. for i in range(n):
  13. sum+=a[i]
  14. if sum<=m:
  15. ans+=1
  16. else:
  17. sum-=a[l]
  18. l+=1
  19. print(ans)
Runtime error #stdin #stdout #stderr 0.16s 23660KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
EOFError: EOF when reading a line