Advertisement
gruslan

shag_2020_11_1_6

Mar 31st, 2023 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. abitur_dict = {}
  2. title_list = []
  3. vuz_dict_count = {}
  4. for _ in range(int(input())):
  5.     title, count = input().split()
  6.     title_list.append(title)
  7.     vuz_dict_count[title] = int(count)
  8.  
  9.     while True:
  10.         word = input()
  11.  
  12.         if not word:
  13.             break
  14.  
  15.         name, *scores, wish = word.split()
  16.         scores = list(map(int, scores))
  17.  
  18.         abitur_dict[name] = abitur_dict.get(name, {'wish': {}})
  19.         abitur_dict[name]['scores'] = [sum(scores)] + scores
  20.         abitur_dict[name]['wish'][title] = int(wish)
  21.  
  22. abitur_list = sorted(
  23.     list(abitur_dict.keys()),
  24.     key=lambda x: abitur_dict[x]['scores'],
  25.     reverse=True
  26. )
  27.  
  28. vuz_dict = {}
  29. for name in abitur_list:
  30.     wish = sorted(
  31.         list(abitur_dict[name]['wish'].keys()),
  32.         key=lambda x: abitur_dict[name]['wish'][x]
  33.     )
  34.  
  35.     for title in wish:
  36.         vuz_dict[title] = vuz_dict.get(title, [])
  37.         if len(vuz_dict[title]) < vuz_dict_count[title]:
  38.             vuz_dict[title].append(name)
  39.             break
  40.         else:
  41.             scores = abitur_dict[name]['scores']
  42.             last_scores = abitur_dict[vuz_dict[title][-1]]['scores']
  43.             if scores == last_scores:
  44.                 vuz_dict[title].append(name)
  45.                 break
  46.  
  47. for title in title_list:
  48.     name_list = vuz_dict.get(title, [])
  49.     print(title, len(name_list))
  50.     print(*sorted(name_list), sep='\n')
  51.  
Tags: olimp shag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement