Advertisement
giGii

f3_B

Mar 26th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. def comparator(item_1, item_2):
  2.     if (item_1[0] == item_2[0]) and (item_1[1] == item_2[1]):
  3.         return item_1 < item_2
  4.     else:
  5.         return item_1 > item_2
  6.  
  7.  
  8. def quick_sort(arr, l_bound=None, r_bound=None, switches=None):
  9.     l_bound = 0 if l_bound is None else l_bound
  10.     r_bound = len(arr) - 1 if r_bound is None else r_bound
  11.  
  12.     middle = l_bound + (r_bound - l_bound) // 2
  13.     pivot = arr[middle]
  14.  
  15.     left = l_bound
  16.     right = r_bound
  17.  
  18.     if r_bound - l_bound <= 1:
  19.         if comparator(arr[r_bound], arr[l_bound]):
  20.             arr[l_bound], arr[r_bound] = arr[r_bound], arr[l_bound]
  21.         return
  22.  
  23.     # while right > left:
  24.     while switches != 0:
  25.         switches = 0
  26.         while comparator(arr[left], pivot) and left < right:
  27.             left += 1
  28.         while comparator(pivot, arr[right]) and left < right:
  29.             right -= 1
  30.         flag = True if middle in (left, right) else False
  31.         if comparator(arr[right], arr[left]):
  32.             arr[left], arr[right] = arr[right], arr[left]
  33.             left += 1
  34.             right -= 1
  35.             switches += 1
  36.         if flag:
  37.             left = l_bound
  38.             right = r_bound
  39.             pivot = arr[middle]
  40.  
  41.     quick_sort(arr, l_bound, middle)
  42.     quick_sort(arr, middle, r_bound)
  43.  
  44.  
  45. n = int(input())
  46. participants = []
  47. for participant in range(n):
  48.     line = input().split()
  49.     participants.append((int(line[1]), -int(line[2]), line[0]))
  50.  
  51. quick_sort(participants)
  52. for participant in participants:
  53.     print(participant[2])
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement