Advertisement
mfgnik

Untitled

Jan 16th, 2021
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import itertools
  2. n = int(input())
  3. fragments = []
  4. lengthes = []
  5. for i in range(n):
  6.     amount, length = map(int, input().split())
  7.     lengthes.append(length)
  8.     fragments.append(list(map(int, input().split())))
  9. for permutation in itertools.permutations(range(n)):
  10.     current = []
  11.     current_length = 0
  12.     for element in permutation:
  13.         current.extend(map(lambda x: x + current_length, fragments[element]))
  14.         current_length += lengthes[element]
  15.     current_distance = current[1] - current[0]
  16.     flag = True
  17.     for i in range(1, len(current)):
  18.         if current[i] - current[i - 1] != current_distance:
  19.             flag = False
  20.             break
  21.     if flag:
  22.         print("YES")
  23.         print(*map(lambda x: x + 1, permutation))
  24.         break
  25. else:
  26.     print("NO")
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement