Last time I didn't move my head today, so I only solved one question.
#36 ARC086-A
** Thoughts ** TLE when counting for all elements. Since count cannot be used, after sorting, the number of elements is counted by comparing adjacent elements. If the element type $ set (a) $ is greater than $ k $, add to ans in ascending order from $ set (a) $.
n, k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = []
c = 1
for i in range(n-1):
if a[i] != a[i+1]:
count.append(c)
c = 1
else:
c += 1
if i == n - 2:
count.append(c)
l = len(count)
#print(a)
#print(count)
c = 0
if l <= k:
print(0)
else:
count.sort()
for i in range(l):
l -= 1
c += count[i]
if l <= k:
print(c)
quit()
count is slow. (Probably $ O (N) $). see you.
Recommended Posts