Advertisement
Pastehsjsjs

Untitled

Mar 10th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | Source Code | 0 0
  1. with open('26.txt', 'r') as f:
  2. data = [[int(q.strip()) for q in i.split()]for i in f.read().strip().split('\n')]
  3. first, second = [i[0] for i in data], [i[1] for i in data]
  4.  
  5. sec = True
  6. val = 7300
  7. S = 0
  8.  
  9. cor = [7300]
  10.  
  11. def find_in_f(v):
  12. for idx, val in enumerate(first):
  13. if v - val >= 5:
  14. return idx, val
  15. return None, None
  16.  
  17. def find_in_s(v):
  18. for idx, val in enumerate(second):
  19. if v - val >= 5:
  20. return idx, val
  21. return None, None
  22.  
  23.  
  24. while True:
  25. if sec:
  26. idx, v = find_in_f(val)
  27. if not v:
  28. break
  29. val = v
  30. sec = False
  31. S += v
  32. cor.append(v)
  33. else:
  34. idx, v = find_in_s(val)
  35. if not v:
  36. break
  37. val = v
  38. sec = True
  39. S += v
  40. cor.append(v)
  41.  
  42. print(cor)
  43. print(sum(cor), len(cor))
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement