[[1, 23], [2, 17], [3, 54], [4, 20], [5, 38]]
20
1 [1, 7]
2 [7]
3 [2, 3, 8]
4 [4]
5 [5, 6]
def bubble_sort(lst): n = len(lst) for i in range(0, n-1): for j in range(n-1, i, -1): if lst[j-1][1] < lst[j][1]: tmp = lst[j] lst[j] = lst[j-1] lst[j-1] = tmp if lst[i][1] == 0: break return def group(data, m): n = len(data) a = [] for i in range(n+1): a.append([]) gnum = 0 for i in range(n): while data[i][1] >= m: gnum += 1 k = data[i][0] a[k].append(gnum) __________ bubble_sort(data) b = [] for i in range(m): b.append([]) i = 0 while i < n and data[i][1] != 0: __________ while j < m and len(b[j]) == 0: j += 1 if j < m: v = b[j].pop() else: gnum += 1 v = gnum a[data[i][0]].append(v) __________ i += 1 data.sort(key=lambda x: x[0]) for i in range(len(data)): num = data[i][0] print(num, a[num]) dt = input() data = __import__("json").loads(dt) m = int(input()) group(data, m)