line1 = input() line2 = input() # no = int(line1) nums = list(map(int, line2.split(" "))) from collections import Counter, deque counts = Counter(nums) freqs = list(counts.values()) freqs.sort() freqs = deque(freqs) no = 0 while len(freqs) > 0: cur = freqs.pop() cur -= 1 no += 1 while len(freqs) > 0 and cur > 0: if freqs[0] <= cur: cur -= freqs.popleft() else: freqs[0] -= cur cur = 0 print(no)
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 | line1 = input() line2 = input() # no = int(line1) nums = list(map(int, line2.split(" "))) from collections import Counter, deque counts = Counter(nums) freqs = list(counts.values()) freqs.sort() freqs = deque(freqs) no = 0 while len(freqs) > 0: cur = freqs.pop() cur -= 1 no += 1 while len(freqs) > 0 and cur > 0: if freqs[0] <= cur: cur -= freqs.popleft() else: freqs[0] -= cur cur = 0 print(no) |