Advertisement
jootiee

Untitled

Apr 11th, 2022
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import numpy as np
  2. from copy import deepcopy as copy
  3. # 2 2 2 2 2 2 2 2 2 2 0
  4.  
  5. file = "/Users/jootiee/Documents/IT/ege/igor/1104/27-A.txt"
  6.  
  7. k = 10
  8.  
  9.  
  10.  
  11. with open(file, "r") as f:
  12.     data = list(map(int, f.readlines()))
  13.     sums = [0] * k
  14.  
  15.     bestsum = 0
  16.  
  17.     for line in data[1:5]:
  18.         x = int(line)
  19.  
  20.         for i in range(k):
  21.             if x % 2:
  22.                 if (sums[i] or i == 0):
  23.                     sums[i] += x
  24.             else:
  25.                
  26.                 # prev_S_rolled = np.roll(S.copy(), 1)
  27.                 prev_S_rolled = copy([sums[k - 1]] + sums[:-1])
  28.                 # print(sums, prev_S_rolled)
  29.                 if (prev_S_rolled[i] or (i == 1)):
  30.                     sums[i] = prev_S_rolled[i] + x
  31.  
  32.         print(sums)
  33.         # print()
  34.         # print(prev_S_rolled)
  35.         bestsum = max(sums[0], bestsum)
  36.  
  37.     print(bestsum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement