Advertisement
Korotkodul

D_py1

Dec 10th, 2022 (edited)
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. import itertools
  2. n = int(input())
  3. ar = list(map(int, input().split()))
  4.  
  5. sh = True
  6.  
  7. best = sum(ar) + 100
  8. ans = []
  9.  
  10. flr = []
  11. for i in range(1, n + 1):
  12.     flr.append(i)
  13.  
  14.  
  15. idx = list(set(itertools.permutations(flr)))
  16.  
  17. if sh:
  18.     print(idx)
  19.  
  20. for var in idx:
  21.     S = 0
  22.     for i in range(n):
  23.         S += ar[i] / var[i]
  24.     if sh:
  25.         print(var)
  26.         print(S)
  27.     if S < best:
  28.         best = S
  29.         ans = var
  30.     if sh:
  31.         print()
  32. if sh:
  33.     print("best ans")
  34.     print(best)
  35.     print(ans)
  36.     print()
  37.  
  38. get = []
  39. for i in range(n):
  40.     get.append(0)
  41. for i in range(n):
  42.     get[i] = ar[ ans[i] - 1]
  43.    
  44.        
  45. print(get)
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement