Team Formation

  • + 0 comments

    import heapq

    def pop_from(dict, key): val = heapq.heappop(dict[key]) if len(dict[key]) == 0: del dict[key] return val

    def push_into(dict, key, value): if key not in dict: dict[key] = [] heapq.heapify(dict[key]) heapq.heappush(dict[key], value)

    t = int(input()) for _ in range(t): A = list(map(int, input().split())) n = A[0] if n ==0: print(0) else: A = sorted(A[1:]) teams = {} for i in range(n): if A[i] - 1 in teams: size = pop_from(teams, A[i] - 1) push_into(teams, A[i], size + 1) else: push_into(teams, A[i], 1)

        min_size = 999999
        for each in teams.values():
            min_pot = min(each)
            if min_pot < min_size:
                min_size = min_pot
        if min_size != 999999:
            print(min_size)