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: Wrong Answer

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

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

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

ans = 0
count = 0

for key, value in d:
    ans = ans + value
    count = count + 1
    if count == x:
        print(ans)
        break

Submission status: Wrong Answer

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

A_set = set(A)

l = len(A_set)
if l>=K:
    print(l-K)
else:
    print(0)

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if A[i] in dic:
        dic[A[i]] += 1
    else:
        dic[A[i]] = 1

ks = list(dic.keys())
vs = list(dic.values())

vs.sort()

B = (len(ks))
cnt = 0

for i in range(len(vs)):
    if B > K:
        B -= vs[i]
        cnt += vs[i]
    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(max(a)+1)]
if len(set(a)) <= k:
    print(0)
    exit()
for i in range(n):
    r[a[i]] += 1
t = []
for i in range(len(r)):
    if r[i]:
        t.append(r[i])
t = list(map(lambda x:-x,t))
heapq.heapify(t)
print(n+sum(t[:k]))

Submission status: Wrong Answer

Solution code:
import heapq
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(max(a)+1)]
if len(set(a)) <= 2:
    print(0)
    exit()
for i in range(n):
    r[a[i]] += 1
t = []
for i in range(len(r)):
    if r[i]:
        t.append(r[i])
t = list(map(lambda x:-x,t))
heapq.heapify(t)
print(n+sum(t[:k]))

Submission status: Wrong Answer

Solution code:
import heapq
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(max(a)+1)]
if len(set(a)) <= 2:
    print(0)
    exit()
for i in range(n):
    r[a[i]] += 1
r = list(map(lambda x:-x,r))
heapq.heapify(r)
print(n+(r[0]+r[1]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
def groupby(src_list):
  dest_list=[[src_list[0],1]]
  print(dest_list)
  for i in range(1,len(src_list)):
    if dest_list[-1][0]==src_list[i]:
      dest_list[-1][1]+=1
    else:
      dest_list.append([src_list[i],1])
  return dest_list
b=groupby(a)
b.sort(key=lambda x:x[1],reverse=True)
l=len(b)
ans=0
for i in range(k,l):
  ans+=b[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
c = 0
list_A = Counter(list(map(int,input().split())))
t = len(list_A.keys())-k
if t<=0:
  print(0)
else:
  B =sorted(list_A.items(),key=lambda x:x[1])
  for j in range(t):
    c += B[j][1]
print(c)

Submission status: Wrong Answer

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

a_cnt = [0] * (N + 1) 
for i in a:
    a_cnt[i] += 1

ans = 0
import numpy as np
while np.count_nonzero(a_cnt) > K:
    #print(a_cnt)
    ans += np.argmax(a_cnt)
    a_cnt[np.argmax(a_cnt)] = 0

print(ans)

Submission status: Wrong Answer

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

if len(set(A))<=k:
    print(0)
else:
    d = {i:0 for i in set(A)}
    for a in A:
        d[a] += 1
    ans = list(d.values())
    print(sum(ans[k:]))

Submission status: Wrong Answer

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

d = {i:0 for i in set(A)}
for a in A:
    d[a] += 1
ans = list(d.values())
ans.sort
print(sum(ans[k:]))

Submission status: Wrong Answer

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

d = {i:0 for i in list(set(A))}
for a in A:
    d[a] += 1
ans = list(d.values())
print(sum(ans[k:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cnt = 0
ans = 0
for k, v in C.items():
    cnt += 1
    if cnt > K:
        ans += v

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = sorted(list(collections.Counter(a).values()))
print(sum(c[:k-1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=Counter(a).most_common()
ans=0
idx=1
while k>0:
  k-=c[-idx][1]
  ans+=c[-idx][1]
  idx+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n,k = map(int, input().split())
A = Counter(map(int, input().split()))

rep_n = len(A)-k

if rep_n==0:
  print(0)
else:
  ans = 0
  for k, v in A.most_common()[::-1]:
    ans += v
    rep_n -= 1
    if rep_n==0:
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A1=list(set(A))
ans=[]
ans2=0
for i in range(len(A1)):
    ans.append(A.count(A1[i]))
ans1=sorted(ans,reverse=True)
for n in range(K,len(A1)):
    ans2+=ans[n]
print(ans2)

Submission status: Wrong Answer

Solution code:
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
count = 1
chk = []
p = 1
if n == 1:
  print(0)
  exit()
else:
  for i in range(n-1):
    if a[i] != a[i+1]:
      count += 1
      chk.append(p)
      p = 1
    else:
      p += 1
  if a[-1] == a[-2]:
    chk.append(p)
  else:
    chk.append(1)
  chk.sort()
  print(chk)
  print(count)
  if count <= k:
    print(0)
    exit()
  else:
    print(sum(chk[:count-k]))
    exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

aa = Counter(a)
ans = 0

if len(aa) > k:
	value = sorted(aa.values())
	ans = sum(value[:k-len(aa)-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
def main():
  N, K = map(int, input().split())
  A =list(map(int, input().split()))
  LA = list(collections.Counter(A).values())
  Ans = N-sum(LA[0:K])
  if Ans > 0:
    print(Ans)
  else:
    print(0)
main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
lis=[]
if len(set(l))<=k:
  print(0)
else:
  li=list(set(l))
  for i in range(len(li)):
    lis.append(l.count(li[i]))
lis.sort()
sum=0
for i in range(len(lis)-k):
  sum+=lis[i]
print(sum)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split(" ")]
setlst = {int(x) for x in input().split(" ")}

swap = 0

if len(setlst)-K > 0:
  swap = len(setlst)-K
else:
  swap = 0

print(swap)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split(" ")]
setlst = {int(x) for x in input().split(" ")}

print(K-len(setlst))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
x = len(set(a))
if x <= k:
    print(ans)
else:
    b = Counter(a).most_common(x)
    for i in range(x-1,k-1,-1):
        print(i)
        ans += b[i][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections 
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    if k != 0:
        c = sorted(b.items(),key=lambda x:x[1])
        for i in range(len(c)):
            num_keys -= c[i][1]
#           c[-1][1] += c[i][1] 
            ans += c[i][1]
            if num_keys <= k:
                break
    else:
        ans += k
            
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    b = sorted(b.items(),key=lambda x:x[1])
    for i in range(len(b)):
        ans += b[i][1]
        num_keys -= b[i][1]
        if num_keys <= k:
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    b = sorted(b)
    for i in range(len(b)):
        ans += b[i]
        num_keys -= b[i]
        if num_keys <= k:
            break
            
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
A = [int(n) for n in input().split()]
kind = dict()

for n in A:
    if n not in kind:
        kind[n] = 0
    kind[n] += 1

print(kind)

diff = len(kind) - int(K)
if diff > 0:
    values = sorted(kind.values())
    print(sum(values[:diff]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
A = [int(n) for n in input().split()]
B = list()
for n in A:
    if n not in B:
        B.append(n)
ANS = len(B) - int(K)
if ANS > 0:
    print(ANS)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, k = map(int, input().split())
c = Counter(list(map(int, input().split())))

print(sum(sorted(c.values())[k:]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=np.zeros(N)
for i in A:
  B[i-1]+=1
C=sorted([i for i in B if i != 0])
ans=0
for i in range(len(C)-K):
  ans+=C[i]

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import Counter

n, k = map(int, input().split())
c = Counter(list(map(int, input().split())))
x = {k : v for k, v in sorted(c.items(), reverse=True, key=itemgetter(1))}

result = 0
for v in list(x.values())[k:]:
  result += v
print(result)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = set((int(x) for x in input().split()))

if k >= len(a):
  print(0)
else:
  k = len(a) - k
  a = list(a)
  a.sort()
  result = 0
  for i, e in enumerate(a):
    if i == k:
      break
    result += e
  print(result)

Submission status: Wrong Answer

Solution code:
def main():
    n, target = map(int, input().split())
    count = {}
    numbers = list(map(int, input().split()))
    for num in numbers:
        if num in count:
            count[num] += 1
        else:
            count[num] = 1
    count = sorted(count.values(), key=lambda x: x)
    print(sum(count[:target - 1]) if len(count) > target else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
dic = {}
B = []
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
for v in dic.values():
  B.append(v)
B.sort()
if len(B) <= K:
  print(0)
else:
  print(sum(B[K:]))

Submission status: Wrong Answer

Solution code:
n, k= map(int, input().split())
a = list(map(int, input().split()))
print(len(set(a))-k+1 if len(set(a))>k else 0)

Submission status: Wrong Answer

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

c = Counter(A)
# print('c', c)
c = sorted(c, reverse=True)
# print('c', c)

ans = sum(c[K:])
# print('c[k:]', c[K:])
print(ans)

Submission status: Wrong Answer

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

a.sort()

count = 0
num_count = 1
num_count_list = list()
for i in range(1, n):
    if(a[i] == a[i - 1]):
        num_count += 1
    else:
        num_count_list.append(num_count)
        num_count = 1
        count += 1

num_count_list.append(num_count)
if(num_count == 1):
    count += 1

num_count_list.sort()
result = 0
if(count > k):
    loop = count - k

    for i in range(loop):
        result += num_count_list[i]

print(result)

Submission status: Wrong Answer

Solution code:
import collections as c

n,k = map(int,input().split())
l = list(map(int,input().split()))
count = c.Counter(l)
ans = 0
check = 0
right = len(count)-k
if right == 0:
    print(0)
    exit()
for i,j in count.most_common()[::-1]:
    ans += j
    check += 1
    if check == right:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
import collections as c

n,k = map(int,input().split())
l = list(map(int,input().split()))
count = c.Counter(l)
ans = 0
check = 0
right = len(count)-k
for i,j in count.most_common()[::-1]:
    ans += j
    check += 1
    if check == right:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, k = list(map(int, input().split()))
balls = list(map(int, input().split()))
b_list = set(balls)
nums = len(b_list)

yoso, s_yoso = [], []
counter = Counter(balls)
kakikae, t = 0, 1
if nums > k:
    for i, v in counter.most_common():
        yoso += [v]

if nums <= k:
    print(0)
else:
    s_yoso = sorted(yoso, reverse=True)
    while nums - k > t:
        kakikae += s_yoso[t-1]
        t += 1
    print(kakikae)

Submission status: Wrong Answer

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

count = 0
if len(c) <= k:
    print(0)
else:
    for i in c:
        o.append(a.count(i))
    o.sort()
    dec =len(c)-k
    print(o[:dec])
    count=sum(o[:dec])
    print(count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
for i in range(1,10):
    if i in a:
        cnt_list.append(a.count(i))
    else:
        continue
cnt_list.sort()
ans = 0
if len(cnt_list) <= k:
    ans = 0
else:
    tmp = len(cnt_list) - k
    ans = sum(cnt_list[:tmp])
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in a:
  d[i]+=1
if len(d)<=k:
  print(len(d))
else:
  print(sum(sorted(list(d.values()))[:len(d)-k]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in a:
  d[i]+=1
print(sum(sorted(list(d.values()))[:n-k]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
l = [d[key] for key in d]
l.sort()
if len(l) < k:
  print(0)
else:
  print(n - sum(l[:k]))

Submission status: Wrong Answer

Solution code:
str = input().split(" ")
num = input().split(" ")

goal = int(str[1])
arr = {}

for i in num:
	i = int(i)

	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

arr = dict(sorted(arr.items(), key=lambda d: d[1], reverse=True))

count = 0
if len(arr.items()) >= goal:
	for index, (i, key) in enumerate(arr.items()):
		if (index + 1) > goal:
			count += key
else:
	count = goal - len(arr.items())

print(count)

Submission status: Wrong Answer

Solution code:
str = input().split(" ")
num = input().split(" ")

goal = int(str[1])
arr = {}

for i in num:
	i = int(i)

	if arr.get(i, False):
		arr[i] += 1
	else:
		arr[i] = 1

arr = dict(sorted(arr.items(), key=lambda d: d[1], reverse=True))

count = 0
for index, (i, key) in enumerate(arr.items()):
	if (index + 1) > goal:
		count += key

print(count)

Submission status: Wrong Answer

Solution code:
a = input()
print(a.count("1"))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=sorted(list(map(int, input().split())))
ll=[]
cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    cont=1
ll.append(l.count(l[-1]))
sorted(ll)

print(sum(ll[k:]))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=sorted(list(map(int, input().split())))
ll=[]
cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    cont=1
ll.append(l.count(l[-1]))
ll.reverse()

print(sum(ll[k:]))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
l=sorted(list(map(int, input().split())))
ll=[]
t=1
cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    t+=1
    cont=1
ll.append(l.count(l[-1]))

print(sum(ll[k:]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = sorted(c.values(), reverse=True)
ans = 0
for x in d:
    if K < len(d):
        ans += d.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=set(map(int,input().split()))
print(max(0,len(a)-k))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

A.sort()
num = len(list(set(A)))
c = [0] * A[-1]
for a in A:
    c[a - 1] += 1
c.sort()
ans = 0
if num > K:
    for i in range(num - K):
        ans += c[i]

print(ans)

Submission status: Wrong Answer

Solution code:



def main()->None:
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    if len(A) > K:
        set_A = set(A)
        count = []
        for s_a in set_A:
            card = A.count(s_a)
            count.append(card)
        sorted_count = sorted(count)
        print(sorted_count)
        reduce_num = len(count) - K
        print(reduce_num)
        sum_count = 0
        counter = 0
        for c in sorted_count:
            if counter == reduce_num :
                break
            sum_count += c
            counter += 1

        print(sum_count)
    else:
        print(0)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lst = list(map(int, input().split()))
ans = 0
for i in lst:
  if (i > K):
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
B=collections.Counter(A)
C=sorted(list(B.values()))
if len(C)<=K:
  answer=0
else:
  answer=sum(C[:K-len(C)-1])
print(answer)

Submission status: Wrong Answer

Solution code:
dbflag=0
def debug(*args):
  if dbflag: print(*args)

result = -1


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

#リスト型
A = [int(i) for i in input().split(' ')]

bag = {}

for x in A:
	if x in bag:
		bag['x'+str(x)]+=1
	else:
		bag['x'+str(x)] = 1

debug(bag)
L = sorted(bag.items(),key= lambda x:x[1])
debug(L)
cnt = len(L) - K

if cnt > 0:
	result = sum(y[1] for y in L[0:K])
	debug([y[1] for y in L[0:K]])
else:
	result = 0


print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
n,k = map(int, input().split())
a = list(map(int, input().split()))
print(sum(list(Counter(a).values())[k:]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
ans = 0
while True:
    if len(set(a_list)) > k:
        if len(set(a_list)) == k+1:
            a_list.pop()
            ans += 1
        else:
            a_list = set(a_list).pop()
            ans += 1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

lenght = len(set(A))-K
ans = 0
if lenght<0:print(ans)
else:
    for k, v in Counter(A).most_common()[::-1][:lenght]:
        ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

lenght = len(set(A))-K
if lenght<0:print(0)
else:print(len(Counter(A).most_common()[::-1][lenght:]))

Submission status: Wrong Answer

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

count = collections.Counter(list_a)
sort_c = sorted(count.items(), key=lambda x:x[1])
num_kind = len(sort_c)

result = 0
for i in range(num_kind - k):
  result += sort_c[i][1]

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = set(a)
c = [a.count(i) for i in b]
d = len(b)
ans = 0
for i in c:
  if K >= d:
    break
  ans += i
  d -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = set(a)
c = [a.count(i) for i in b]
d = len(b)
ans = 0
while 1:
  if K >= d:
    break
  ans += min(c)
  d -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = set(list(map(int,input().split())))
if len(a) > K:
  print(len(a) - K)
else:
  print('0')

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
B = sorted([int(i) for i in input().split()])
D ={}
bag = 0

for i in B:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1

S = list(D.values())
if len(D) - K <= 0:
    print(0)
else:
    for i in range(1, len(D)-K+1):
        bag += S[-i]
    print(bag)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
B = sorted([int(i) for i in input().split()])
D ={}
bag = 0

for i in B:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1

S = list(D.values())
if len(D) - K <= 0:
    print(0)
else:
    for i in range(1, len(D)-K+1):
        bag += S[-i]
print(bag)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A = set(map(int,input().split()))
print(max(0,len(A)-K))

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = list(set(B))
D ={}
bag = 0

for i in C:
    D[i] = 0
    for j in B:
        if i == j:
            D[i] += 1

LLL = list(D.values())

if len(D) <= K:
    print(0)
else:
    AA = len(D) - K
    for i in range(-AA, 0):
        bag += LLL[i]
    print(bag)

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = list(set(B))
D ={}
bag = 0
for i in C:
    D[i] = 0
    for j in B:
        if i == j:
            D[i] += 1
if len(D) <= K:
    print(0)
else:
    LLL = list(D.values())
    AA = len(D) - K
    for i in range(-AA, 0):
        bag += LLL[i]
    print(bag)

Submission status: Wrong Answer

Solution code:
import collections
N,K=map(int,input().split())
a=list(map(int,input().split()))
table=collections.defaultdict(int)
for i in range(N):
  table[a[i]]+=1
print(abs(len(list(table.keys()))- K))

Submission status: Wrong Answer

Solution code:
import collections
N,K=map(int,input().split())
a=list(map(int,input().split()))
table=collections.defaultdict(int)
for i in range(N):
  table[a[i]]+=1
print(len(list(table.keys()))- K)

Submission status: Wrong Answer

Solution code:
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, k, *a = (int(x) for x in sys.stdin.read().split())

    c = collections.Counter(a)
    diffs = len(c)
    if diffs <= k: print(0); exit()
    remainder = diffs - k
    count = 0
    l = sorted(c.values())
    b = collections.Counter(l)
    for i, j in sorted(b.items()):
        if remainder - j > 0:
            count += j * i
        else:
            count += remainder * i
            break
    
    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

Solution code:
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, k, *a = (int(x) for x in sys.stdin.read().split())

    c = collections.Counter(a)
    diffs = len(c)
    if diffs <= k: print(0); exit()
    remainder = diffs - k
    count = 0
    l = sorted(c.values())
    b = collections.Counter(l)
    for i, j in b.items():
        if remainder - j > 0:
            count += j * i
        else:
            count += remainder * i
            break
    
    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

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

dic = {}
for num in a:
    if num not in dic.keys():
        dic[num] = 0
    dic[num] += 1

dic = sorted(dic.items(), key=lambda x:x[1])

ans = 0

if len(dic) <= k:
    print(0)
else:
    for i in range(len(dic)- k):
        ans += dic[i][1]

print(ans)

Submission status: Wrong Answer

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

a.sort()

dic = {}
for num in a:
    if num not in dic.keys():
        dic[num] = 0
    dic[num] += 1

ans = 0

dic = sorted(dic.items(), key=lambda x:x[1])

ans = 0

if len(dic) <= k:
    print(0)
else:
    for i in range(len(dic)- k):
        ans += dic[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
count=[0]*n
for i in range(n):
  count[a[i]-1] += 1
count.sort()
sum=0
print(count)
for i in range(k):
  sum += count[n-1-i]
print(max(0,n-sum));

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
count=[0]*n
for i in range(n):
  count[a[i]-1] += 1
count.sort()
sum=0
for i in range(k):
  sum += count[i]
print(max(0,n-sum));

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
sorted_nums = list(sorted(nums.items(), key=lambda x: x[1]))
nums_len = len(sorted_nums)
ans = 0
if nums_len > K:
    for i in range(nums_len - K):
        ans += sorted_nums[i][1]
        print(i, sorted_nums[i][0], sorted_nums[i][1])
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Not so Diverse
N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
count = 1
ans = 0
B = []

for i in range(1,N+1):
    if i == N:
        if A[i-1] == A[i - 2]:
            count += 1
            B.append(count)
        else:
            count = 1
            B.append(count)
    elif A[i] == A[i-1]:
        count += 1
    else:
        B.append(count)
        count = 1
B.sort()

for j in range(len(B)-K):
    ans += B[j]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    A = "".join(input().split())
    c = sorted(collections.Counter(A).values())
    k = len(c) - K
    if k <= 0:
        print(0)
    else:
        print(sum(c[:k]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    A = "".join(input().split())
    c = sorted(collections.Counter(A).values())

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
print(max(0,len(set(l))-k))

Submission status: Wrong Answer

Solution code:
n,k=map(lambda x: int(x), input().split())
a=list(map(lambda x: int(x), input().split()))
dic={}
for i in range(n):
    dic[a[i]]=dic.get(a[i],0)+1
count=list(dic.values())
count.sort(reverse=True)
print(count)
if len(count) <= k:
    print(0)
else:
    print(sum(count[k:]))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int, input().strip().split()))
import collections
c = collections.Counter(a)

cnt = 0
res = 0
for i in c.most_common():
    if cnt >= k:
        res+=1
    else:
        cnt+=1
        
print(cnt)

Submission status: Wrong Answer

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

c=Counter(A)
cnt=[]
for i in range(len(set(A))):
  cnt.append(c.most_common()[i][0])
cnt.sort()
ans=0
while len(cnt)>k:
  ans+=cnt[0]
  cnt=cnt[1:]
print(ans)

Submission status: Wrong Answer

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

c=collections.Counter(A)
cnt=[]
for i in range(len(set(A))):
  cnt.append(c.most_common()[i][0])
ans=0
while len(cnt)>k:
  ans+=cnt[0]
  cnt=cnt[1:]
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
print (N - bisect.bisect(A, K+0.5))

Submission status: Wrong Answer

Solution code:
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
print (N - bisect.bisect_right(A, K))

Submission status: Wrong Answer

Solution code:
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
print (N - bisect.bisect(A, K))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
print(max(len(set(A))-K,0))

Submission status: Wrong Answer

Solution code:
import sys
N, K = map(int, input().split())
a = list(map(int, input().split()))

seta = set(a)
cntK = len(seta)
cnta = [0] * cntK
if cntK <= K:
    print(0)
    sys.exit()

for i in range(len(seta)):
    cnta[i] = a.count(seta.pop())

cnta.sort()
cnt = 0
for i in range(K - 1):
    cnt += cnta[i]

print(cnt)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=set(a)
if len(a)>k:
    print(len(a)-k)
else:
    print(0)

Submission status: Wrong Answer

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

if len(set(li)) <= b:
    print(0)
cnt = 0
for i in range(len(li)-1):
    if li[i]!=li[i+1]:
        cnt += 1
        if cnt == b:
            print(len(li)-i-1)
            break