-
Notifications
You must be signed in to change notification settings - Fork 0
/
1100.py
60 lines (43 loc) · 1.57 KB
/
1100.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 1100
# solved
# use dictionary to solve this problem
# m (amount of solved problems) will be keys, id (team num) will be items
# fill dictionary, create list of keys and sort it, then print keys and items
# do not convert teams' ids into strings, it takes too much time
def merge_sort(array):
if len(array) > 1:
mid = len(array) // 2
left = array[:mid]
right = array[mid:]
left = merge_sort(left)
right = merge_sort(right)
sorted_array = []
while len(left) > 0 and len(right) > 0:
if left[0] < right[0]:
sorted_array.append(left.pop(0))
else:
sorted_array.append(right.pop(0))
for i in left:
sorted_array.append(i)
for i in right:
sorted_array.append(i)
else:
sorted_array = array
return sorted_array
n = int(input())
input_dict = {}
for i in range(n):
input_data = input().split(' ')
team = input_data[0]
problems_amount = int(input_data[1])
teams_with_problems_amount = []
if problems_amount in input_dict.keys():
teams_with_problems_amount = input_dict[problems_amount]
teams_with_problems_amount.append(team)
input_dict[problems_amount] = teams_with_problems_amount
input_dict_keys = merge_sort(list(input_dict.keys()))
for i in range(len(input_dict_keys))[::-1]:
problems_amount = input_dict_keys[i]
teams_with_problems_amount = input_dict[problems_amount]
for j in range(len(teams_with_problems_amount)):
print(teams_with_problems_amount[j], problems_amount)