n = int(input()) t = [0] * 500001 for x in input().split(): t[int(x)] += 1 t = [i for i in t if i != 0] t.sort() m = max(t) c = [len([x for x in t if x == i]) for i in range(m,0,-1)] counter = 0 j = 0 while j < len(c) -1: e = c[j] * (2 * m - 1) if n-e >= 0: counter += c[j] n -= e else: ee = int(n / (2 * m - 1) + 1) counter += ee n -= ee * (2 * m - 1) break j += 1 m -= 1 if n > 0: counter += n print(counter)
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 | n = int(input()) t = [0] * 500001 for x in input().split(): t[int(x)] += 1 t = [i for i in t if i != 0] t.sort() m = max(t) c = [len([x for x in t if x == i]) for i in range(m,0,-1)] counter = 0 j = 0 while j < len(c) -1: e = c[j] * (2 * m - 1) if n-e >= 0: counter += c[j] n -= e else: ee = int(n / (2 * m - 1) + 1) counter += ee n -= ee * (2 * m - 1) break j += 1 m -= 1 if n > 0: counter += n print(counter) |