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:
nums , types = map(int, input().split())
array = list(map(int,input().split()))
array.sort()
type_count = 0
count = 0
result = 0
ary_count = []
array.append(1000000000)

for i in range (nums):
    if array[i] == array[i +1]:
        count += 1
    elif array[i] < array[i +1]:
        ary_count.append(count)
        type_count += 1
        count = 0

if type_count > types:
    for i in range(type_count - types):
        result += min(ary_count)+1
        ary_count.pop(ary_count.index(min(ary_count)))

print(result)

Submission status: Time Limit Exceeded

Solution code:
nums , types = map(int, input().split())
array = list(map(int,input().split()))
array.sort()
type_count = 0
count = 0
array.append(1000000000)
result = 0

for i in range (nums):
    if array[i] < array[i+1]:
        type_count += 1

if type_count > types:
    for i in range(type_count - types):
        change = nums

        for x in range(nums):
            if array[x] == array[x+1]:
                count += 1
            elif array[x] < array[x+1]:
                if count < change :
                    change = count
                    str = x
                count = 0

        result += (change+1)
        for y in range (change+1):
            array.pop(str-y)
        nums -= (change+1);

print(result)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

c = collections.Counter(A)
n = len(c)

cnt = 0
if n - K > 0:
    for i in range(n - K):
        cnt += c.most_common()[::-1][i][1]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = 0
for t in range(n):
    if len(set(a)) <= k:
        print(b)
        break
    else:
        c = Counter(a)
        d = min(c, key=c.get)
        e = max(c, key=c.get)
        a = [e if i == d else i for i in a]
        b = b + c[d]

Submission status: Time Limit Exceeded

Solution code:
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
sum = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
for i in range(K,tmp,1):
    sum += li.most_common()[i][1]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    B = set(A)
    for i in B:
        L.append(A.count(i))
    L.sort()
    if len(B) <= K:
        print('0')
    else:
        print(str(sum(L[0:len(B)-K])))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = set(A)
L = []
for i in B:
    tmp = 0
    while i in A:
        A.remove(i)
        tmp += 1
    L.append(tmp)
L.sort()
if len(B) <= K:
    print('0')
else:
    print(str(sum(L[0:len(B)-K])))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(input().split())
B = set(A)
L = []
for i in B:
    L.append(A.count(i))
L.sort()
if len(B) <= K:
    print('0')
else:
    print(str(sum(L[0:len(B)-K])))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = set(A)
L = []
for i in B:
    L.append(A.count(i))
L.sort()
if len(B) <= K:
    print('0')
else:
    print(str(sum(L[0:len(B)-K])))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = []
for i in set(A):
    L.append(A.count(i))
L.sort()
if len(set(A)) <= K:
    print('0')
else:
    print(str(sum(L[0:len(set(A))-K])))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = [0] * len(set(A))
tmp = 0
for i in set(A):
    L[tmp] = A.count(i)
    tmp += 1
L.sort()
if len(set(A)) <= K:
    print('0')
else:
    print(str(sum(L[0:len(set(A))-K])))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = [0] * len(set(A))
tmp = 0
for i in set(A):
    L[tmp] = A.count(i)
    tmp += 1
L.sort()
if len(set(A)) <= K:
    print('0')
else:
    print(str(sum(L[0:len(set(A))-K])))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
d = []
c = []
for i in range(n):
    if not a[i] in d:
        d.append(a[i])
        c.append(a.count(a[i]))
c.sort(reverse=True)
print(n-sum(c[0:k]))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
d = []
c = []
for i in range(n):
    if not a[i] in d:
        d.append(a[i])
        c.append(a.count(a[i]))
c.sort()
print(sum(c[0:len(d)-k]))

Submission status: Time Limit Exceeded

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

A_dict = {}
rewrite = 0

for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

while len(A_dict) > K:
    rewrite_key = min(A_dict, key=A_dict.get)
    rewrite += A_dict[rewrite_key]
    del A_dict[rewrite_key]

print(rewrite)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a_tuple = tuple(map(int, input().split()))
a_set = set(a_tuple)
count_list = []

if k >= len(a_set):
    print(0)
else:
    for i in a_set:
        count = a_tuple.count(i)
        count_list.append(count)
    count_list.sort()
    ans = sum(count_list[:len(a_set)-k])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_set = set(a_list)
count_list = []

if k >= len(a_set):
    print(0)
else:
    for i in a_set:
        count = a_list.count(i)
        count_list.append(count)
    count_list.sort()
    ans = sum(count_list[:len(a_set)-k])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_set = set(a_list)
count_list = []

if k >= len(a_set):
    print(0)
else:
    for i in a_set:
        count = a_list.count(i)
        count_list.append(count)
    count_list.sort()
    ans = sum(count_list[:len(a_set)-k])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
for i in a:
    d[i]=d.get(i,0)+1
c=0
while len(d)>k:
    x=min(d, key=d.get)
    c+=d[x]
    del d[x]
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [None]*N
    A = list(map(int, input().split()))
    Adict = [0]*N
    for a in A:
        Adict[a-1] += 1
    num = len(set(A))
    while(0 in Adict):
        Adict.remove(0)
    Adict = sorted(Adict,reverse=True)
    count=0
    for _ in range(num - K):
        count += Adict.pop()
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
nums=[int(i) for i in input().split()]
num_num = [0]*(n+1)
for i in range(1, n+1):
  num_num[i] = nums.count(i)

num_num.sort()
num_num.remove(0)
l = len(num_num)
kaisu = l - k

ans = 0
for i in range(kaisu):
  atai = int(num_num.pop(0))
  ans += atai
print(ans)

Submission status: Time Limit Exceeded

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

typ = list(set(lst))
NumList = []
for i in range(len(typ)):
    c = lst.count(typ[i])
    NumList.append([typ[i],c])
NumList.sort(key = lambda x:x[1])
cnt = 0
for i in range(len(typ) - k):
    cnt += NumList[i][1]
print(cnt)

Submission status: Time Limit Exceeded

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

    c = collections.Counter(A)

    i = 0
    ans = 0
    for num, cnt in c.most_common()[::-1]:
        if i >= len(set(A)) - K:
            break
        ans += cnt
        i += 1

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import collections

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

c = collections.Counter(A)

i = 0
ans = 0
for num, cnt in c.most_common()[::-1]:
    if i >= len(set(A)) - K:
        break
    ans += cnt
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

l=[]
for i in range(N+1):
  l.append(A.count(i))

ls = sorted(l,reverse=True)

print(sum(ls[K:]))

Submission status: Time Limit Exceeded

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

l=[]
for i in range(N+1):
  l.append(A.count(i))

ls = sorted(l,reverse=True)

ans = N
for j in range(K):
  ans -= ls[j]

print(ans)

Submission status: Time Limit Exceeded

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

l=[]
for i in range(N+1):
  l.append(A.count(i))

ls = sorted(l,reverse=True)

j= K
ans = 0
while ls[j] != 0:
  ans += ls[j]

print(ans)

Submission status: Time Limit Exceeded

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

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
dic = {}
ans = 0
for i in range(N):
    if A[i] not in dic:
        dic[A[i]] = 1
    else:
        dic[A[i]] += 1
for j in range(len(dic) - K):
    max_k = min(dic, key=dic.get)
    ans += dic.pop(max_k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
binary = [0 for _ in range(n)]
ls = list(map(int, input().split()))
for i in ls:
    binary[i-1] += 1
binary = sorted(binary)

ans = 0
while k < len(binary):
    ans += binary[0]
    binary.pop(0)
print(ans)

Submission status: Time Limit Exceeded

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

A_set = list(set(A))
if len(A_set) <= K:
  print(0)
else:
  AA = [A.count(i) for i in A_set]
  AA.sort()
  ans = sum(AA[:-K])
  print(ans)

Submission status: Time Limit Exceeded

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

A_set = list(set(A))
if len(A_set) <= K:
  print(0)
else:
  AA = [A.count(i) for i in A_set]
  AA.sort(reverse=True)
  ans = sum(AA[K:])
  print(ans)

Submission status: Time Limit Exceeded

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

a_set = set(a_list)
a_set_len = len(a_set)
a_count = sorted([a_list.count(i) for i in a_set])

count = 0
for i in range(max((a_set_len - k), 0)):
    count += a_count[i]

print(count)

Submission status: Time Limit Exceeded

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

a_set = set(a_list)
a_set_len = len(a_set)
a_count = sorted([a_list.count(i) for i in a_set])

count = 0
i = 0
while(a_set_len > k):
    count += a_count[i] 
    a_set_len -= 1
    i += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
N, K = map(int, input().split())
a_lis = [int(_) for _ in input().split()]
count = 0
counter = sorted(Counter(a_lis).items(), key=lambda x: x[1])
while len(counter) > K:
    count += counter[0][1]
    del counter[0]
    if len(counter) == K:
        print(count)
        sys.exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
N, K = map(int, input().split())
a_lis = [int(_) for _ in input().split()]
count = 0
counter = sorted(Counter(a_lis).items(), key=lambda x: x[1])
while len(counter) > K:
    count += counter[0][1]
    counter.pop(0)
    if len(counter) == K:
        print(count)
        sys.exit()
print(0)

Submission status: Time Limit Exceeded

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

#まとめる
a_set = list(set(a))

#数えてソートする
a_cnt =[0 for i in range(len(a_set))]
for i in range(len(a_set)):
    a_cnt[i] = a.count(a_set[i])
a_cnt.sort() 
#種類の数はa_setの要素数
num_typ = len(a_set)
#数が少ない数値から書き換えていく
if num_typ <= k:
    print(0)
else:
    print(sum(a_cnt[:len(a_cnt)-k]))

Submission status: Time Limit Exceeded

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

#まとめる
a_set = list(set(a))
a_cnt =[0 for i in range(len(a_set))]
#数えてソートする
for i in range(len(a_set)):
    a_cnt[i] = a.count(a_set[i])
a_cnt.sort() 
#種類の数はa_setの要素数
num_typ = len(a_set)
#数が少ない数値から書き換えていく
if num_typ <= k:
    print(0)
else:
    print(sum(a_cnt[:len(a_cnt)-k]))

Submission status: Time Limit Exceeded

Solution code:

N,K = map(int,input().split())

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

dic = {}

for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

lis = []

for i in dic:

    lis.append(dic[i])

lis.sort()

ans = 0

"""
num = len(lis) - K
if num < 0:
    num = 0

for i in range(num):
    ans += lis[i]
"""
lo = len(lis)

while lo > K:
 
    ans += lis[0]
    del lis[0]
    lo = len(lis)

print (ans)

Submission status: Time Limit Exceeded

Solution code:

N,K = map(int,input().split())

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

dic = {}

for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

lis = []

for i in dic:

    lis.append(dic[i])

lis.sort()

ans = 0

cnt = 0
while len(lis) > K:

    ans += lis[0]
    del lis[0]

    cnt += 1
    if cnt > 200000:
        break

print (ans)

Submission status: Time Limit Exceeded

Solution code:

N,K = map(int,input().split())

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

dic = {}

for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

lis = []

for i in dic:

    lis.append(dic[i])

lis.sort()

ans = 0

while len(lis) > K:

    ans += lis[0]
    del lis[0]

print (ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, K = map(int, input().split())
l = list(input().split())

l_set = set(l)
syukei = []
for i in l_set:
    syukei.append(l.count(i))
    syukei.sort()
    
if len(syukei)-K > 0:
    print(sum(syukei[:len(syukei)-K]))
else:
    print(0)

Submission status: Time Limit Exceeded

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

l_set = set(l)
syukei = []
for i in l_set:
    syukei.append(l.count(i))
    syukei.sort()
    
if len(syukei)-K > 0:
    print(sum(syukei[:len(syukei)-K]))
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
aList = list(map(int, input().split()))
aKinds = list(set(aList))
if k > len(aKinds):
    print(0)
    exit()
else:
    aDict = {}
    for a in aKinds:
        aDict[a] = aList.count(a)
    aDictSorted = sorted(aDict.items(), key=lambda x: -x[1])
    count = 0
    for a in aDictSorted[k:]:
        count += a[1]
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
kinds = len(set(A))
count = []

for i in set(A):
  count.append(A.count(i))

rest = kinds - K
if rest > 0: 
  print(sum(sorted(count)[:rest]))
else: 
  print(0)

Submission status: Time Limit Exceeded

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

count = [0] * N

for i in range(N):
    count[i] = A.count(i+1)

count.sort(reverse = True)

ans = 0
for j in range(K):
    ans += count[j]
    
print (N-ans)

Submission status: Time Limit Exceeded

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

num_dups = []
a_set = set(a)
for elem in a_set:
    num_dups.append(a.count(elem))

num_dups.sort(reverse=True)

ball_to_replace = len(a_set) - k

result = 0
for i in range(ball_to_replace):
    result += num_dups.pop()

print(result)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A1:
    AN[a] = A.count(a)
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
seta = set(a)
dic = {}
for i in seta:
  dic[i] = a.count(i)

dic = sorted(dic.items(), key=lambda x:x[1])
typeCnt = len(seta) - k
cnt = 0
if typeCnt > 0:
  for i in range(typeCnt):
    cnt = cnt + dic[i][1]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
num = list(set(A))
ans=[]
for n in num:
    ans.append(A.count(n))
print(sum(sorted(ans)[:len(ans)-K:]))

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
num = list(set(A))
#print(num)
ans=[]
for n in num:
    #print(n,"=",A.count(n))
    ans.append(A.count(n))
#print(ans)
#print(len(ans),"種類")
ans.sort()
total=0
for i in range(len(ans)-K):
    total+=ans[i]
print(total)

Submission status: Time Limit Exceeded

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

A.sort()

C = []
i = 0
while i <= N-1:
  j = A[i]
  k = A.count(j)
  C.append(k)
  i += k

C.sort()


x = 0
for i in range(max(0, len(C)-K)):
    x += C[i]
    N -= C[i]
    
print(x)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=input().split()
B=Counter(A)
C=sorted(B.items(),key=lambda x: -x[1])
print(sum(C[K:][i][1] for i in range(len(C[K:]))))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=input().split()
B=Counter(A).most_common()
print(sum(B[K:][i][1] for i in range(len(B[K:]))))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=Counter(A).most_common()
print(sum(B[K:][i][1] for i in range(len(B[K:]))))

Submission status: Time Limit Exceeded

Solution code:
import collections
N,K=map(int,input().split())
A=map(int,input().split())
B=collections.Counter(A).most_common()
print(sum(B[K:][i][1] for i in range(len(B[K:]))))

Submission status: Time Limit Exceeded

Solution code:
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=collections.Counter(A).most_common()
print(sum(B[K:][i][1] for i in range(len(B[K:]))))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=Counter(list(map(int,input().split())))
cnt=0
ls=[]
if len(a)>k:
	for i in range(len(a)):
		ls.append(a.most_common()[i][1])
print(sum(ls[k:]))

Submission status: Time Limit Exceeded

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

balls = list(map(int,input().split()))

max_n = 200000

ball_counts = [0]*max_n

for ball in balls:
    ball_counts[ball-1] += 1


counts = []

for n in ball_counts:
    if n !=0:
        counts.append(n)
        
counts = sorted(counts)

c = 0

while len(counts) > k:
    c += counts[0]
    del counts[0]

print(c)

Submission status: Time Limit Exceeded

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

balls = list(map(int,input().split()))

unique_ball = []

for ball in balls:
    if not (ball in unique_ball):
        unique_ball.append(ball)

ball_counts = []

for ball in unique_ball:
    ball_counts.append(balls.count(ball))
    
ball_counts = sorted(ball_counts)

c = 0

while len(ball_counts) > k:
    c += ball_counts[0]
    del ball_counts[0]

print(c)

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).most_common()
c.sort(key=lambda x: x[1])
ans = 0
while len(c) > K:
    ans += c.pop(0)[1]
print(ans)

Submission status: Time Limit Exceeded

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

balls = list(map(int,input().split()))

unique_ball = []

for ball in balls:
    if not (ball in unique_ball):
        unique_ball.append(ball)

ball_counts = []

for ball in unique_ball:
    ball_counts.append(balls.count(ball))

c = 0

while len(unique_ball) > k:
    c += ball_counts[ball_counts.index(min(ball_counts))]
    del unique_ball[ball_counts.index(min(ball_counts))]
    del ball_counts[ball_counts.index(min(ball_counts))]
    
print(c)

Submission status: Time Limit Exceeded

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

a = [0]*n
for i in range(n):
  a[i]=lst.count(i+1)
a.sort(reverse=True)
ans = 0
for i in range(k):
  if a[i] == 0:
    ans = n
  else:
    ans += a[i]
print(n-ans)

Submission status: Time Limit Exceeded

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

a = [0]*200000
for i in range(200000):
  a[i]=lst.count(i+1)
a.sort()
ans = 0
for i in range(k):
  if a[-1] == 0:
    ans = n
  else:
    ans += a[-1]
    del a[-1]
print(n-ans)

Submission status: Time Limit Exceeded

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

a=[]#種類の記憶
for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
c.sort()
ans = 0
if k < len(c):
  for i in range(k):
    ans += c[-1]
    del c[-1]
  print(n-ans)
else:
  print(0)

Submission status: Time Limit Exceeded

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

a=[]#種類の記憶

for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
ans = 0
while k < len(c):
  i = c.index(min(c)) #最小の個数のインデックス
  ans += min(c)
  del c[i]
print(ans)

Submission status: Time Limit Exceeded

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

a=[]#種類の記憶
for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
ans = 0
while k < len(a):
  i = c.index(min(c)) #最小の個数のインデックス
  ans += min(c)
  del a[i]
  del c[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = [int(x) for x in input().split()][1]
num_list = [int(x) for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
for i in range(0, k):
    if num_dict:
        num_dict.pop(max(num_dict, key=num_dict.get))
    else:
        print(0)
        break
else:
    print(sum(num_dict.values()))

Submission status: Time Limit Exceeded

Solution code:
[n, k] = [int(x) for x in input().split()]
num_list = [int(x) for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
for i in range(0, k):
    if num_dict:
        num_dict.pop(max(num_dict, key=num_dict.get))
    else:
        print(0)
        break
else:
    print(sum(num_dict.values()))

Submission status: Time Limit Exceeded

Solution code:
[n, k] = [int(x) for x in input().split()]
num_list = [x for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
for _ in range(0, k):
    if num_dict:
        num_dict.pop(max(num_dict, key=num_dict.get))
    else:
        print(0)
        break
else:
    print(sum(num_dict.values()))

Submission status: Time Limit Exceeded

Solution code:
[n, k] = [int(x) for x in input().split()]
num_list = [x for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
for i in range(0, k):
    if num_dict:
        num_dict.pop(max(num_dict, key=num_dict.get))
    else:
        print(0)
        break
else:
    print(sum(num_dict.values()))

Submission status: Time Limit Exceeded

Solution code:
[n, k] = [int(x) for x in input().split()]
num_list = [x for x in input().split()]
for i in range(0, k):
    max_count, max_num = 0, ""
    for x in num_list:
        if num_list.count(x) > max_count:
            max_count = num_list.count(x)
            max_num = x
    else:
        num_list = [x for x in num_list if not x == max_num]
print(len(num_list))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
n_count = []
for a in set(A):
    n_count.append(A.count(a))
print(sum(sorted(n_count)[:len(set(A)) - K]))

Submission status: Time Limit Exceeded

Solution code:
# 数字の数、数字の種類を取得
setting_num = list(map(int, input().split()))

# ボールの数字を取得
ball_num = list(map(int, input().split()))

# ボールの数字の種類
distinct_num = set(ball_num)

# １種類のボールの数
num_counts = list()

# それぞれの種類のボールの数を取得
for num in distinct_num:
    num_counts.append(ball_num.count(num))

num_counts.sort(reverse=True)

operate_count = 0

for i in range(setting_num[1], len(num_counts)):
    operate_count += num_counts[i]

print(operate_count)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
countNum = {}
ans = 0
for i in setA:
    countNum[i] = a.count(i)
max_v = max(countNum.values())

keys = [k for k, v in countNum.items() if v == max_v]
for w, v in sorted(countNum.items(), key=lambda x: x[1]):
    if k < len(set(a)):
        while w in a:
            aIndex = a.index(w)
            a.pop(aIndex)
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

numbers = set(A)
numbers = [A.count(n) for n in numbers]
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))

Submission status: Time Limit Exceeded

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

numbers = set(A)
numbers = {n: A.count(n) for n in numbers}
numbers = [A.count(n) for n in numbers]
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))

Submission status: Time Limit Exceeded

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

numbers = set(A)
numbers = {n: A.count(n) for n in numbers}
numbers = list(numbers.values())
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))

Submission status: Time Limit Exceeded

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

numbers = {a: A.count(a) for a in A}
numbers = list(numbers.values())
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=list(set(A))
c=len(b)
d=c-K
ans=0
count=[]
for i in range(c):
    count.append(A.count(b[i]))
count.sort()
for i in range(d):
    ans+=count[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=list(set(A))
b.sort()
c=len(b)
d=c-K
ans=0
count=[]
for i in range(len(b)):
    count.append(A.count(b[i]))
count.sort()
for i in range(d):
    ans+=count[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


N, K = map(int, input().split())
A = list(map(int, input().split()))
A_unique = list(set(A))
A_list = []
if len(A_unique) <= K:
    print(0)
    exit()
else:
    del_num = len(A_unique) - K
    for i in A_unique:
        A_list.append(A.count(i))
    A_list.sort()
    print(sum(A_list[:del_num]))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_unique = list(set(A))
A_list = []
if len(A_unique) <= K:
    print(0)
    exit()
else:
    del_num = len(A_unique) - K
    for i in A_unique:
        A_list.append(A.count(i))
    A_list.sort()
    print(sum(A_list[:del_num]))

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
ball_set = set(balls)
freqs = list(balls.count(i) for i in ball_set)
freqs.sort(reverse=True)
print(sum(freqs[k:]))

Submission status: Time Limit Exceeded

Solution code:
import collections

N, K = map(int, input().split())
A = map(int, input().split())
counter = 0
collection = collections.Counter(A)
k = len(collection)
if k > K:
  change_n = k - K
  for i in range(change_n):
    min_k = collection.most_common()[-1-i][1]
    counter += min_k

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections

N, K = map(int, input().split())
A = map(int, input().split())
counter = 0
collection = collections.Counter(A)
k = len(collection)
if k > K:
  change_n = k -K
  for i in range(change_n):
    min_k = collection.most_common()[-1-i][1]
    counter += min_k

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import re

a = input()
a = re.split(" ",a)

b = input()
b = re.split(" ",b)
b = list(map(int,b))
c = set(b)
c = list(map(int,c))
if((len(b) <= int(a[1])) or (len(c) <= len(a[1]))):
    print(0)
else:
    save = []
    for i in range(len(c)):
        x = b.count(c[i])
        save.append(int(x))
    save.sort()
    y = len(c)-int(a[1])
    ans = 0
    for i in range(int(y)):
        ans += int(save[i])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

a = input()
a = re.split(" ",a)

b = input()
b = re.split(" ",b)
b = list(map(int,b))
c = set(b)
d = list(map(int,c))
if(len(b) <= int(a[1])):
    print(0)
else:
    save = []
    for i in range(len(d)):
        x = b.count(d[i])
        save.append(int(x))
    save.sort()
    y = len(d)-int(a[1])
    ans = 0
    for i in range(int(y)):
        ans += int(save[i])
    print(ans)