Problem:


Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

10 3
5 1 3 2 4 1 1 2 3 4

Sample Output 3

3



Sample input:
5 2
1 1 2 2 5


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
cc=list(set(c))
d=len(cc)
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(cc[i])
f.sort()
ans=0
if e>=0:
    print(0)
else:
    print(sum(f[:abs(e)]))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(list(set(c))[i])
f.sort()
ans=0
if e>=0:
    print(0)
else:
    print(sum(f[:abs(e)]))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(list(set(c))[i])
f.sort()
ans=0
if e>=0:
    print(0)
else:
    j=0
    while e<0:
        ans+=f[j]
        j+=1
        e+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python
#coding: utf-8

N, K = map(int, raw_input().split())
l = map(int, raw_input().split())

s = list(set(l))
num = range(len(s))
if len(s) <= K: print 0
else:
    for i in range(len(s)):
        num[i] = len([j for j in l if j == s[i]])
    sousa = len(s)-K
    num.sort()
    print sum(num[:sousa])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, raw_input().split())
l = map(int, raw_input().split())

s = list(set(l))
num = range(len(s))
if len(s) <= K: print 0
else:
    for i in range(len(s)):
        num[i] = l.count(s[i])
    sousa = len(s)-K
    num.sort()
    print sum(num[:sousa])

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    exit
else:
    count=[0]*len(As)
    for i in range(len(As)):
        count[i]=int(A.count(As[i]))
    num=sorted(count)
    num2=num[0:sa]
    ans=0
    for i in num2:
        ans+=i
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    exit
else:
    count=[0]*len(As)
    for i in range(len(As)):
        count[i]=A.count(As[i])
    num=sorted(count)
    ans=0
    for i in range(sa):
        ans+=num[i]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    exit
else:
    count=[]
    for i in As:
        count.append(A.count(i))
    num=sorted(count)
    ans=0
    for i in range(sa):
        ans+=num[i]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=len(As)-K
count=[]
for i in As:
    count.append(A.count(i))
num=sorted(count)
ans=0
for i in range(sa):
    ans+=num[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N , K = map(int,input().split())
A = list(map(int,input().split()))
count_num = []
num = []
for i in range(N):
	if A[i] in num:
		count_num[num.index(A[i])][0] += 1
	else:
		num.append(A[i])
		count_num.append([1,A[i]])
		
count_num.sort(reverse = True)

top_K_count = 0
for i in range(K):
	if i < len(count_num):
		top_K_count += count_num[i][0]
print(N - top_K_count)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
num=list(map(int,input().split()))
a=[0]*n
for x in num:
    a[x-1]+=1
a=sorted(a)
for i in range(n):
    if a[i]!=0:
        del a[:i]
        break
ans=0
while len(a)>k:
    ans+=a[0]
    a.pop(0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

result = 0
n,k = map(int,input().split())
input_list = input().split()
counter_list = collections.Counter(input_list)
if k < len(counter_list):
  for i in range(len(counter_list)-k):
    result += sorted(counter_list.values())[i]
print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
if len(c.keys()) <= k:
    print(0)
    exit()
else:
    ans = 0
    lis = list(c.values())
    lis.sort()
    while(len(lis) > k):
        ans += lis.pop(0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
for i in range(1, num+1):
    ans += d.most_common()[-i][1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
dic = list(set(A))

if len(dic) <= K:
  print(0)
else:
  count_list = []
  for i in range(len(dic)):
    count_list.append(A.count(dic[i]))
  
  count_list.sort()
  print(sum(count_list[:len(dic)-K]))

Submission status: Time Limit Exceeded

Solution code:
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
a = collections.Counter(A)
c = len(A)
for i in range(K):
    try:
        c -= a.most_common()[i][1]
    except IndexError:
        print(c)
        exit()
print(c)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

import collections

c = collections.Counter(A)
values, counts = zip(*c.most_common()[::-1])
counts = list(counts)
cnt = 0
inf = 10 ** 18


for _ in range(inf):
  if len(counts) <= K:
    print(cnt)
    break

  cnt +=  counts[0]  
  counts = counts[1:]

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
seta=set(a)

mylist=[a.count(i) for i in seta]
mylist.sort(reverse=True)

#print(mylist)
val=sum(mylist[:k])
  
print(n-val)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
seta=set(a)
lenseta=len(seta)

mylist=[a.count(i) for i in seta]
mylist.sort(reverse=True)

#print(mylist)
val=sum(mylist[:k])
  
print(n-val)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)

mylist=[0 for i in range(n)]
for i in range(n):
  mylist[i]=a.count(i)
mylist.sort(reverse=True)

val=sum(mylist[:k])
  
print(n-val)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)

mylist=[0 for i in range(n)]
for i in range(n):
  mylist[i]=a.count(i)
mylist.sort(reverse=True)

val=0
for i in range(0,k):
  val+=mylist[i]
  
print(n-val)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)

mylist=[]
for i in range(n):
  mylist.append(a.count(i))
mylist.sort(reverse=True)

val=0
for i in range(0,k):
  val+=mylist[i]
  
print(n-val)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)
mydict={}
mylist=[]
for i in a:
    if i not in mydict:
        mydict[i]=a.count(i)
z=len(mydict)-k

for i in mydict.values():
  mylist.append(i)

#print(mydict)
if z<=0:
    print(0)
else:
    ans=0
    for i in range(z):
        tmp=min(mylist)
        ans+=tmp
        mylist.remove(tmp)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)
mydict={}
mylist=[]
for i in a:
    if i not in mydict:
        mydict[i]=a.count(i)

for i in mydict.values():
  mylist.append(i)
mylist.sort()      
z=len(mydict)-k
#print(mydict)
if z==0:
    print(0)
else:

    ans=0
    for i in range(z):
        ans+=mylist[i]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
countlist = []
for i in range(N):
    countlist.append(A.count(i+1))

print(max(0, N-sum(sorted(countlist)[:-K-1:-1])))

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
num = len(set(A))
if num-K <= 0:
    print(0)
else:
    countlist = []
    for i in range(N):
        res = A.count(i+1)
        if res != 0:
            countlist.append(res)
    print(sum(sorted(countlist)[:num-K]))

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
num = len(set(A))
if num-K <= 0:
    print(0)
else:
    countlist = []
    for i in range(N):
        res = A.count(i+1)
        if res != 0:
            countlist.append(res)
    countlist = sorted(countlist)
    print(sum(countlist[:num-K]))

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
num = len(set(A))
if num-K <= 0:
    print(0)
else:
    countlist = []
    for i in range(N):
        if A.count(i+1) != 0:
            countlist.append(A.count(i+1))
    countlist = sorted(countlist)
    print(sum(countlist[:num-K]))

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(i) for i in input().split())
a = [int(i)-1 for i in input().split()]

count_list = [0]*n
for i in range(n):
    count_list[i] = a.count(i)

print(n-sum(sorted(count_list, reverse=True)[:k]))

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]

dic = list(set(a))
if len(dic) <= k:
    print(0)
    exit()

n_ = len(dic) - k

count_list = []
for i in dic:
    count_list.append(a.count(i))

print(sum(sorted(count_list)[:n_]))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
b = set(a)
for s in b:
    cnt_list.append(a.count(s))
cnt_list = sorted(cnt_list)

print(sum(cnt_list[:len(cnt_list) - k]))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
b = set(a)
for s in b:
    cnt_list.append(a.count(s))
cnt_list = sorted(cnt_list)

print(sum(cnt_list[:len(cnt_list) - k]) if len(cnt_list) - k > 0 else 0)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
cnt_list = []
b = set(a)
for s in b:
    cnt_list.append(a.count(s))
cnt_list = sorted(cnt_list)

print(sum(cnt_list[:len(cnt_list) - k]) if len(cnt_list) - k > 0 else 0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  1 01:07:09 2019

@author: yuta
"""

NK = list(map(int,input().split()))
A = list(map(int,input().split()))

"""
TLE解法
def main(nk,a):
    k = nk[1]
    a_uni = list(set(a)) #重複なし数列
    a_uni_num = [0]*len(a_uni) #各数字の重複個数
    for i in range(len(a_uni)):
        for j in range(len(a)):
            if a[j] == a_uni[i]:
                a_uni_num[i] += 1
    a_uni_num_sort = sorted(a_uni_num) #重複個数を昇順で並び替え
    red_num = len(a_uni) - k #減らす種類の数
    print(sum(a_uni_num_sort[:red_num]))

main(NK,A)
"""
def main(nk,a):
    k = nk[1]
    a_uni = list(set(a)) #重複なし数列
    a_uni_num = [0]*len(a_uni) #各数字の重複個数
    for i in range(len(a_uni)):
        a_uni_num[i] = a.count(a_uni[i])
    a_uni_num_sort = sorted(a_uni_num) #重複個数を昇順で並び替え
    red_num = len(a_uni) - k #減らす種類の数
    print(sum(a_uni_num_sort[:red_num]))

main(NK,A)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  1 01:07:09 2019

@author: yuta
"""

NK = list(map(int,input().split()))
A = list(map(int,input().split()))

def main(nk,a):
    k = nk[1]
    a_uni = list(set(a)) #重複なし数列
    a_uni_num = [0]*len(a_uni) #各数字の重複個数
    for i in range(len(a_uni)):
        for j in range(len(a)):
            if a[j] == a_uni[i]:
                a_uni_num[i] += 1
    a_uni_num_sort = sorted(a_uni_num) #重複個数を昇順で並び替え
    red_num = len(a_uni) - k #減らす種類の数
    print(sum(a_uni_num_sort[:red_num]))

main(NK,A)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    d = {str(i):0 for i in a}
    bucket = sorted([a.count(int(i)) for i in d])
    print(sum(bucket[0:len(bucket) - K:]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,k = map(int, input().split())
num = list(map(int, input().split()))
cns = set(num)
f = [num.count(i) for i in cns]
f.sort(reverse=True)
print(sum(f[k::]))

Submission status: Time Limit Exceeded

Solution code:
def quicksort(x):
    if x==[]: return []
    smallerSorted = quicksort([a for a in x[1:] if a <= x[0]])
    biggerSorted = quicksort([a for a in x[1:] if a > x[0]])
    return smallerSorted+[x[0]]+biggerSorted
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    l = set(a)
    bucket = quicksort([a.count(i) for i in l])
    print(sum(bucket[0:len(bucket) - K:]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
num = list(map(int, input().split()))
cns = set(num)
f = []
for i in cns:
    f.append(num.count(i))
f.sort(reverse=True)
print(sum(f[K::]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
l = set(a)
bucket = sorted([a.count(i) for i in l])
print(sum(bucket[0:len(bucket) - K:] + [0]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
num = list(map(int, input().split()))
cns = list(set(num))
f = []
for i in cns:
    f.append(num.count(i))
f.sort(reverse=True)
print(sum(f[K::]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    l = set(a)
    bucket = sorted([a.count(i) for i in l])
    print(sum(bucket[0:len(bucket) - K:]))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = Counter(A).most_common()
dict = []
for l in B:
    dict.append([l[0], l[1]])
dict.sort(key=lambda x:x[1])
count = 0
l = len(B)
if l <= K:
    print(0)
else:
    while l != K:
        count += dict[0][1]
        del dict[0]
        dict.sort(key=lambda x:x[1])
        l = len(dict)
        if l == K:
            break
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = input().split()
A = [int(i) for i in A]


dp = []
i = 0
while(len(A)>0):
    a = A[0]
    A.remove(A[0])
    count = 1
    while(a in A):
        count = count + 1
        A.remove(a)
    dp.append(count)

def solve(dp):
    ans = 0
    if(len(dp)<=K):
        return ans
    else:
        sub = len(dp) - K
        while(sub>0):
            ans = ans + min(dp)
            dp.remove(min(dp))
            sub = sub -1
    return ans
print(solve(dp))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = input().split()
A = [int(i) for i in A]

dp = [0]*(max(A)+1)
for i in range(N):
    dp[A[i]] = dp[A[i]] + 1

def solve(dp):
    ans = 0
    dp = [y for y in dp if y != 0]
    if(len(dp)<=K):
        return ans
    else:
        sub = len(dp) - K
        while(sub>0):
            ans = ans + min(dp)
            dp.remove(min(dp))
            sub = sub -1
    return ans
print(solve(dp))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
set_a = set(a)
ans=0
while len(set_a) > k:
    i = -1
    c = Counter(a).most_common()[i]  # (出現回数の最も少ない数字,出現回数)
    num = c[0]
    ans += c[1]
    set_a.remove(num)
    for _ in range(c[1]):
        a.remove(num)  # リストの操作回数...
    i-=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]
kind = []
for i in range(1,N+1):
    temp = ball.count(i)
    kind.append(temp)
if kind.count(0)>=N-K:
    print(0)
else:
    kind.sort()
    sumNum = 0
    for i in range(N-K):
        sumNum += kind[i]
    print(sumNum)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
A = set(a)
l = len(A)
s = []
if l<=k:
    print(0)
    exit()
else:
    for i in A:
        s.append(a.count(i))
s = sorted(s)
print(sum(s[:l-k]))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

count = dict()
for i in a:
  count[i] = count.get(i, 0) + 1

ans = 0
while len(count) > k:
  key, value = min(count.items(), key=lambda x : x[1])
  del count[key]
  ans += value

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

def solve():
  a.sort()
  c = [a.count(i) for i in range(1,n+1) if a.count(i)>0]
  c.sort()
  if(len(c)<=k):
    print(0)
  else:
    print(sum(c[:len(c)-k]))

solve()

Submission status: Time Limit Exceeded

Solution code:
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
n,k=map(int,input().split())
l=list(map(int,input().split()))
sl=list(set(l))
l2=[]
for i in sl:
  l2.append(struct(i,l.count(i)))
l2=sorted(l2,key=lambda x:x.b)
print(sum(x.b for x in l2[:len(sl)-k]))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n, k = list(map(int, input().split()))
li = list(map(int, input().split()))

s = set(li)
ns = [li.count(i) for i in s]
ns.sort()

if len(ns) <= k:
    print(0)
else:
    print(sum(ns[:-k]))

Submission status: Time Limit Exceeded

Solution code:
import collections
n,k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
ct = 0
for i in range(k):
 try:
  ct += c.most_common()[i][1]
 except:
  break
ans = n-ct
if ans <0:
  ans = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_unique = list(set(A))
N_unique = len(A_unique)



M = N_unique-K
if M <= 0:
	print(0)
	exit()

a = [A.count(list(set(A))[i]) for i in range(N_unique)]
a_sort = sorted(a)

ans = 0
for i in range(0,M):
	ans += a_sort[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_unique = list(set(A))
N_unique = len(A_unique)

a = [A.count(A_unique[i]) for i in range(N_unique)]
a_sort = sorted(a)

M = N_unique-K
if M <= 0:
	print(0)
	exit()

ans = 0
for i in range(0,M):
	ans += a_sort[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_unique = list(set(A))
N_unique = len(A_unique)

a = [A.count(A_unique[i]) for i in range(N_unique)]
a_sort = sorted(a)

M = len(set(A))-K
if M <= 0:
	print(0)
	exit()

ans = 0
for i in range(0,M):
	ans += a_sort[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
A = list(map(int, input().split()))
ind = set(A)
ans = len(ind)
B = []
a = 0
if(ans<=b):
    print(0)
else:
    A.sort()
    num = 0
    while(num<len(A)):
        num = A.count(A[0])
        B.append(num)
        A = A[num:]
        num = 0
    B.sort()
    for i in B:
        ans -= 1
        a+=i
        if(ans <= b):
            break
    print(a)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())

A = list(map(int, input().split()))
ind = set(A)
ans = len(ind)
B = []
a = 0
if(ans<=b):
    print(0)
else:
    for i in ind:
        B.append(A.count(i))
    B.sort()
    for j in B:
        if(ans<=b):
            break
        a+=j
        ans -=1
    print(a)

Submission status: Time Limit Exceeded

Solution code:
blist=[]
n,k=map(int,input().split(" "))
ii=list(map(int,input().split(" ")))
for m in range(0,n):
  blist.append(ii.count(m))
blist.sort(reverse=True)
print (n-sum(blist[kk] for kk in range(0,k)))

Submission status: Time Limit Exceeded

Solution code:
ii=[]
blist=[]
n,k=map(int,input().split(" "))
ii=list(map(int,input().split(" ")))
for m in range(0,n):
  blist.append(ii.count(m))  
blist.sort(reverse=True)
print (n-sum(blist[kk] for kk in range(0,k)))

Submission status: Time Limit Exceeded

Solution code:
ii=[]
blist=[]

n,k=map(int,input().split(" "))
ii=list(map(int,input().split(" ")))
  
for m in range(0,n):
  blist.append(ii.count(m))
  
blist.sort(reverse=True)

print (n-sum(blist[kk] for kk in range(0,k)))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

ii=[]
blist=[]
count=0

n,k=map(int,input().split(" "))
ii=list(map(int,input().split(" ")))
  
for m in range(1,n+1):
  blist.append([m,ii.count(m)])
  
blist.sort(key=itemgetter(1),reverse=True)

print (n-sum(blist[kk][1] for kk in range(0,k)))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

ii=[]
blist=[]
count=0

n,k=map(int,input().split(" "))
ii=list(map(int,input().split(" ")))
  
for m in range(1,n+1):
  blist.append([m,ii.count(m)])
  
blist.sort(key=itemgetter(1),reverse=True)

for p in range(0,k):
  count=count+blist[p][1]
  
print(n-count)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

ii=[]
blist=[]
count=0

n,k=map(int,input().split(" "))
i=input().split(" ")
#print(i)
for mm in range(0,n):
  ii.append(int(i[mm]))
  
for m in range(1,n+1):
  blist.append([m,ii.count(m)])
  
#print(blist)
blist.sort(key=itemgetter(1),reverse=True)
#blist.reverse()
#print(blist)

for p in range(0,k):
  count=count+blist[p][1]
  
print(n-count)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

ii=[]
blist=[]
count=0

n,k=map(int,input().split(" "))
i=input().split(" ")
#print(i)
for mm in range(0,n):
  ii.append(int(i[mm]))
  
for m in range(1,n+1):
  blist.append([m,ii.count(m)])
  
#print(blist)
blist.sort(key=itemgetter(1))
blist.reverse()
#print(blist)

for p in range(0,k):
  count=count+blist[p][1]
  
print(n-count)

Submission status: Time Limit Exceeded

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
dic = {}
for a in A:
    if not(a in dic):
        dic[a]=1
    else:
        dic[a]+=1
val = sorted(dic.values())
# print(val)
rc = len(val) - K
ans = 0
for r in range(rc):
    ans += val[0]
    val = val[1:]
print(ans if ans >=0 else 0)

Submission status: Time Limit Exceeded

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
s = set(A)
for a in A:
    bucket[a]+=1
bucket = [n for n in bucket if n != 0]
rc = len(s) - K
ans = 0
for r in range(rc):
    tminid = bucket.index(min(bucket))
    ans += bucket[tminid]
    bucket[tminid]=200006
print(ans if ans >=0 else 0)

Submission status: Time Limit Exceeded

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
s = set(A)
for a in A:
    bucket[a]+=1
bucket = [n for n in bucket if n != 0]
rc = len(s) - K
ans = 0
for r in range(rc):
    tmin = min(bucket)
    ans += tmin
    bucket[bucket.index(tmin)]=200006
print(ans if ans >=0 else 0)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
A = [item for item in list(map(int, input().split()))]
B = {item:A.count(item) for item in A}
B = list(((key, item) for key, item in B.items()))
B.sort(key=lambda x:x[1], reverse=True)
res = 0
for i in range(k, len(B)):
    res += B[i][1]
print(res)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
dict = {}
for Ai in A:
    if Ai in dict:
        dict[Ai] += 1
    else:
        dict[Ai] = 1
count = 0
while len(dict) > K:
    max_key = max(dict, key=dict.get)
    min_key = min(dict, key=dict.get)
    dict[max_key] += 1
    dict[min_key] -= 1
    count += 1
    if dict[min_key] == 0:
        del dict[min_key]
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]

summary = {}
for a in A:
    if a not in summary.keys():
        summary[a] = 1
    else:
        summary[a] += 1
s_list = list(summary.values())
s_list.sort()
res = 0
while len(s_list) > K:
    res += s_list.pop(0)
print(res)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

def cnt_uniq(li):
    uniq = list(set(li))
    ret = []
    for i in uniq:
        ret.append(li.count(i))
    return ret

uniq = sorted(cnt_uniq(a), reverse = True)[k:]
print(sum(uniq))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

count = 0;

def cnt_uniq(li):
    uniq = []
    for i in li:
        if i not in uniq:
            uniq.append(i)
    ret = []
    for i in uniq:
        ret.append(li.count(i))
    return ret

uniq = sorted(cnt_uniq(a))
while k < len(uniq):
    count += uniq[0]
    uniq.pop(0)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

count = 0;

def uniq(li):
    ret = []
    for i in li:
        if i not in ret:
            ret.append(i)
    return ret

def overwrite(li, target_val, dest_val):
    cnt = 0
    for taple in enumerate(li):
        if taple[1] == target_val:
            li[taple[0]] = dest_val
            cnt += 1
    return [li, cnt]

def detect(li):
    min_num = [float("inf")]
    max_num = [0]
    for i in li:
        if max_num[0] < li.count(i):
            max_num[0] = li.count(i)
            if len(max_num) > 1:
                max_num[1] = i
            else:
                max_num.append(i)

        if min_num[0] >= li.count(i):
            min_num[0] = li.count(i)
            if len(min_num) > 1:
                min_num[1] = i
            else:
                min_num.append(i)

    return [min_num, max_num]


while k < len(uniq(a)):
    min_num, max_num = detect(a)
    a, cnt = overwrite(a, min_num[1], max_num[1])
    count += cnt

print(count)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = []
for r in br:
    cr.append(ar.count(r))
dr = sorted(cr,reverse=True)
print(sum(dr[b:len(ar)]))

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
count = 0
c = len(br)
cr = []
for r in br:
    cr.append(ar.count(r))
dr = sorted(cr)
for i in range(c - b):
    count += dr[i]
print(count)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
count = 0
c = len(br)
cr = []
for r in br:
    cr.append(ar.count(r))
dr = sorted(cr)
while c > b:
    count += dr[0]
    c -= 1
    del dr[0]
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
N,K = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
count = collections.Counter(A)
if len(count.values()) <= K:
    print(0)
else:
    ans = 0
    for i in range(len(count.values()) - K):
        ans += count.most_common()[-(i+1)][1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
kind=set(a)
c=len(kind)
ans=0
if len(kind)<=k:
    print(0)
else:
    for i in kind:
        b.append(a.count(i))
    b.sort()
    for i in range(c-k):
        ans+=b[i]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().strip().split(" ")))
ANS=[]
for i in range(200000):
    ANS.append(A.count(i))
ANS.sort(reverse=True)
B=[e for e in ANS if e>0]

P=[]
if len(B)<=k:
    print(0)
else:
    for i in B[k:]:
        P.append(i)
    print(sum(P))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
total = 0
for i in range(A_len - K):
    total += A_count[i]
print(total)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = [ A_list.count(A) for A in A_index]
A_count.sort()
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = list(set(A_list))
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
D = {}
for i in range(N) :
    if A[i] not in D :
        D[A[i]] = 1
    else :
        D[A[i]] += 1
L = D.values()
L = sorted(L)
ans = 0
for i in range(len(L)) :
    if len(L) > K :
        ans += L[0]
        L.pop(0)
print(ans)