Advertisement
Korotkodul

dem22.n27

Jun 18th, 2023 (edited)
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. f = open('27_A.txt')
  2. #f = open('tst.txt')
  3. n = int(f.readline())
  4. a = [int(i) for i in f.readlines()]
  5. f.close()
  6. a = [0] + a
  7. n += 1
  8. pf = [0] * n
  9.  
  10. for i in range(1, n):
  11.     pf[i] = pf[i-1] + a[i]
  12.  
  13. mxs = 0
  14. ansl = 0
  15.  
  16. for i in range(n):
  17.     for j in range(i+1,n):
  18.         nows = pf[j] - pf[i]
  19.         if nows % 43 == 0:
  20.             if nows > mxs:
  21.                 mxs = nows
  22.                 ansl = j - i
  23.             elif nows == mxs:
  24.                 if j - i < ansl:
  25.                     ansl = j - i
  26. print(ansl, mxs)
  27. print(a)
  28. print(pf)
  29. """
  30. 3 258
  31. [0, 43, 43, 1, 129, 42, 87]
  32. [0, 43, 86, 87, 216, 258, 345]
  33. """
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement