Advertisement
Farz0l1x

Untitled

May 1st, 2024
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. file = open('1A.txt')
  2. N, M = map(int, file.readline().split())
  3. a =[int(x) for x in file]
  4. count = 0
  5. for i in range(N):
  6.     sum = 0
  7.     for j in range(i, N):
  8.         sum += a[j]
  9.         if sum <= M:
  10.             count = max(count, j - i + 1)
  11.         else:
  12.             break
  13. print(count)
  14.  
  15. file = open('1B.txt')
  16. N, M = map(int, file.readline().split())
  17. a = [int(x) for x in file]
  18. ans = 0
  19. l = 0
  20. s = 0
  21. for r in range(N):
  22.     s += a[r]
  23.     while s > M:
  24.         s -= a[l]
  25.         l += 1
  26.     ans = max(ans, r - l + 1)
  27. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement