#!/usr/bin/env python3 from collections import Counter import sys def main(): N = int(input()) A = [int(x) for x in input().split()] if N != len(A): print("N != len(A)") return by_count = Counter(A).most_common() by_count_len = len(by_count) front = 0 back = by_count_len - 1 result = 0 while front < by_count_len and (nlid := by_count[front][1]) != 0: result += 1 nothers = 0 while front < back and nlid > nothers: nothers += by_count[back][1] by_count[back] = (0, 0) back -= 1 if not nlid > nothers: diff = nothers - nlid back += 1 by_count[back] = (0, diff + 1) front += 1 print(result) if __name__ == "__main__": if len(sys.argv) == 2: sys.stdin = open(sys.argv[1]) main()
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 33 34 35 36 | #!/usr/bin/env python3 from collections import Counter import sys def main(): N = int(input()) A = [int(x) for x in input().split()] if N != len(A): print("N != len(A)") return by_count = Counter(A).most_common() by_count_len = len(by_count) front = 0 back = by_count_len - 1 result = 0 while front < by_count_len and (nlid := by_count[front][1]) != 0: result += 1 nothers = 0 while front < back and nlid > nothers: nothers += by_count[back][1] by_count[back] = (0, 0) back -= 1 if not nlid > nothers: diff = nothers - nlid back += 1 by_count[back] = (0, diff + 1) front += 1 print(result) if __name__ == "__main__": if len(sys.argv) == 2: sys.stdin = open(sys.argv[1]) main() |