matacoder

Untitled

Jan 7th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. from random import randint
  2. from sys import getsizeof
  3.  
  4.  
  5. def sub_partition(array, start, end, idx_pivot):
  6.     if not (start <= idx_pivot <= end):
  7.         raise ValueError('idx pivot must be between start and end')
  8.  
  9.     array[start], array[idx_pivot] = array[idx_pivot], array[start]
  10.     pivot = array[start]
  11.     i = start + 1
  12.     j = start + 1
  13.  
  14.     while j <= end:
  15.         if array[j] <= pivot:
  16.             array[j], array[i] = array[i], array[j]
  17.             i += 1
  18.         j += 1
  19.  
  20.     array[start], array[i - 1] = array[i - 1], array[start]
  21.     return i - 1
  22.  
  23.  
  24. def quicksort(array, start=0, end=None):
  25.     if end is None:
  26.         end = len(array) - 1
  27.  
  28.     if end - start < 1:
  29.         return array
  30.  
  31.     idx_pivot = randint(start, end)
  32.     i = sub_partition(array, start, end, idx_pivot)
  33.     # print array, i, idx_pivot
  34.     quicksort(array, start, i - 1)
  35.     quicksort(array, i + 1, end)
  36.     return array
  37.  
  38.  
  39. n = int(input())
  40.  
  41. # all_solved = []
  42.  
  43. db = {}
  44. for i in range(n):
  45.     score = input().split()
  46.     name = score[0]
  47.     solved = int(score[1])
  48.     fee = int(score[2])
  49.     # all_solved.append(solved)
  50.     if solved not in db:
  51.         db[solved] = {}
  52.     if fee not in db[solved]:
  53.         db[solved][fee] = []
  54.         db[solved][fee].append(name)
  55.     else:
  56.         db[solved][fee].append(name)
  57. # print(db)
  58. # print(getsizeof(db))
  59. # print(getsizeof(all_solved))
  60.  
  61. # all_solved = list(set(all_solved))
  62. # all_solved = list(reversed(quicksort([int(i) for i in all_solved])))
  63.  
  64. for solved_item in sorted(db, reverse=True):
  65.     # print(solved_item)
  66.     current_fees = list(db[solved_item].keys())
  67.     # print(current_fees)
  68.     current_fees = quicksort(current_fees)
  69.  
  70.     for current_fee in current_fees:
  71.         # print(current_fee)
  72.         current_names = db[solved_item][current_fee]
  73.         # print(current_names)
  74.         current_names = quicksort(current_names)
  75.         for name_item in current_names:
  76.             print(name_item)
  77.  
Advertisement
Add Comment
Please, Sign In to add comment