Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def comparator(item_1, item_2):
- if (item_1[0] == item_2[0]) and (item_1[1] == item_2[1]):
- return item_1 < item_2
- else:
- return item_1 > item_2
- def quick_sort(arr, l_bound=None, r_bound=None, switches=None):
- l_bound = 0 if l_bound is None else l_bound
- r_bound = len(arr) - 1 if r_bound is None else r_bound
- middle = l_bound + (r_bound - l_bound) // 2
- pivot = arr[middle]
- left = l_bound
- right = r_bound
- if r_bound - l_bound <= 1:
- if comparator(arr[r_bound], arr[l_bound]):
- arr[l_bound], arr[r_bound] = arr[r_bound], arr[l_bound]
- return
- # while right > left:
- while switches != 0:
- switches = 0
- while comparator(arr[left], pivot) and left < right:
- left += 1
- while comparator(pivot, arr[right]) and left < right:
- right -= 1
- flag = True if middle in (left, right) else False
- if comparator(arr[right], arr[left]):
- arr[left], arr[right] = arr[right], arr[left]
- left += 1
- right -= 1
- switches += 1
- if flag:
- left = l_bound
- right = r_bound
- pivot = arr[middle]
- quick_sort(arr, l_bound, middle)
- quick_sort(arr, middle, r_bound)
- n = int(input())
- participants = []
- for participant in range(n):
- line = input().split()
- participants.append((int(line[1]), -int(line[2]), line[0]))
- quick_sort(participants)
- for participant in participants:
- print(participant[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement