import sys n, k = list(map(int, sys.stdin.readline().strip().split())) l = list(map(int, sys.stdin.readline().strip().split())) def judge(l, k): for i in set(l): if l.count(i) == k: return True return False found = False res = 0 while not found: if judge(l, k): print(res) found = True l[l.index(max(l))] -= 1 res += 1 if judge(l, k): print(res) found = True l[l.index(min(l))] += 1 res += 1 但是没通过,不知道咋回事