Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from dataclasses import dataclass
- import functools
- @dataclass
- class Person:
- name: str
- discipline: str
- perf_cnt: int
- penalty: int
- def cmp(a, b):
- if a.perf_cnt > b.perf_cnt:
- return True
- if a.perf_cnt < b.perf_cnt:
- return False
- if a.perf_cnt == b.perf_cnt:
- if a.penalty < b.penalty:
- return True
- return False
- def solve():
- n = int(input())
- dispciplines_info = {}
- ans = []
- for i in range(n):
- tmp = input()
- d = ""
- numb = ""
- d, numb = tmp.split(",")
- dispciplines_info[d] = int(numb)
- k = int(input())
- discipline_candidates = {}
- for i in range(k):
- tmp = input()
- name, discipline, perf_cnt, penalty = tmp.split(",")
- tmp_Person = Person(name, discipline, int(perf_cnt), int(penalty))
- if tmp_Person.discipline not in discipline_candidates:
- discipline_candidates[tmp_Person.discipline] = []
- discipline_candidates[tmp_Person.discipline].append(tmp_Person)
- for d in discipline_candidates:
- discipline_candidates[d] = sorted(discipline_candidates[d], key=functools.cmp_to_key(cmp))
- for d in dispciplines_info:
- for i in range(min(dispciplines_info[d], len(discipline_candidates[d]))):
- ans.append(discipline_candidates[d][i].name)
- ans = sorted(ans)
- print(ans)
- solve()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement