from collections import defaultdict def main(n, tab): count = defaultdict(lambda: 0) for x in tab: count[x] += 1 values = sorted(count.values()) last = 0 ans = 1 for i in range(len(values) - 1, -1, -1): c = values[i] - 1 while c > 0 and last < i and values[last] <= c: c -= values[last] last += 1 if last == i: break if values[last] > c: values[last] -= c ans += 1 print(ans) main(int(input()), list(map(int, input().split())))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from collections import defaultdict def main(n, tab): count = defaultdict(lambda: 0) for x in tab: count[x] += 1 values = sorted(count.values()) last = 0 ans = 1 for i in range(len(values) - 1, -1, -1): c = values[i] - 1 while c > 0 and last < i and values[last] <= c: c -= values[last] last += 1 if last == i: break if values[last] > c: values[last] -= c ans += 1 print(ans) main(int(input()), list(map(int, input().split()))) |