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:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
num = list(map(int, input().split()))
cns = list(set(num))
d = {}
for i in cns:
    d[i] = num.count(i)
sorted(d.items(), key=lambda x: x[1])
sum = 0
for i in d:
    if i > K :
        sum += d[i]
print(sum)

Submission status: Wrong Answer

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])
    count = 0
    for i in bucket:
        count += i
        bucket.pop(0)
        if len(bucket) == K:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = sorted(Counter([int(i) for i in input().split()]).most_common())
cnt = 0
for a in A[K:]:
    cnt += a[1]
print(cnt)

Submission status: Wrong Answer

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

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
solve(dp)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random


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

count_dic = {}

for i in range(len(a)):
    if a[i] in count_dic.keys():
        count_dic[a[i]] += 1
    else:
        count_dic[a[i]] = 1
# print(type(count_dic[1]))

# print(count_dic)
count_list = sorted(count_dic.items(),key=lambda x: x[0])

ans = 0
# print(len(count_list))
while len(count_list)>k:
    # print(count_list)
    delte_tuple = count_list[-1]
    add_tuple = count_list[0]
    count_list[0] = tuple([add_tuple[0],add_tuple[1]+delte_tuple[1]])
    ans += delte_tuple[1]
    del count_list[-1]

print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random


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

count_dic = {}

for i in range(len(a)):
    if a[i] in count_dic.keys():
        count_dic[a[i]] += 1
    else:
        count_dic[a[i]] = 1
# print(type(count_dic[1]))

# print(count_dic)
count_list = sorted(count_dic.items(),key=lambda x: x[0])

ans = 0
# print(len(count_list))
while len(count_list)>k:
    # print(count_list)
    delte_tuple = count_list[-1]
    add_tuple = count_list[0]
    count_list[0] = tuple([add_tuple[0],add_tuple[1]+delte_tuple[1]])
    ans += delte_tuple[1]
    del count_list[-1]

print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random


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

count_dic = {}

for i in range(len(a)):
    if a[i] in count_dic.keys():
        count_dic[a[i]] += 1
    else:
        count_dic[a[i]] = 1
# print(type(count_dic[1]))

print(count_dic)
count_list = sorted(count_dic.items(),key=lambda x: x[0])

ans = 0
# print(len(count_list))
while len(count_list)>k:
    # print(count_list)
    delte_tuple = count_list[-1]
    add_tuple = count_list[0]
    count_list[0] = tuple([add_tuple[0],add_tuple[1]+delte_tuple[1]])
    ans += delte_tuple[1]
    del count_list[-1]

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 1

t = sorted(d.items(), key = lambda x: -x[1])

cnt = 0
for k, v in t[-K:]:
  cnt += v
print(cnt)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]
kind = list(set(ball))
if len(kind) <= K:
    print(0)
else:
    kind.sort()
    sumNum = 0
    for i in range(len(kind)-K):
        sumNum += kind[i]
    print(sumNum)

Submission status: Wrong Answer

Solution code:
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
A = set(a)
l = len(A)
s = list(collections.Counter(A).values())
s = sorted(s)
print(sum(s[0:l-k]))

Submission status: Wrong Answer

Solution code:
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
A = set(a)
l = len(A)
s = list(collections.Counter(A).values())
s = sorted(s)
print(sum(s[l-k:]))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc081/tasks/arc086_a
import sys


variety = 0  # 数字の種類
element1 = 0
def main():
    n, k = input().split()
    #N = int(n)
    K = int(k)

    numeric = input().split()  # サイズがわからなくてもこれでリストとして格納できる
    #list(map(int, numeric)) <-これもいいけど
    numeric = [int(x) for x in numeric]  # リストを返すなら内包表記の方が速い

    # 数字の種類の判定アルゴリズム

    numeric.sort()  # まずはソートをして
    #print(numeric)

    # まずnumeric内に何種類の数字があるかを判定。n種類ぶんのリスト(vary)を用意、１つずつ格納しておく
    vary = []  # 種類を格納
    TypeDetermination(numeric, vary)  # 何種類あるか判定
    #print(variety,vary)

    # そのリストを使って、その数が何個numericにあるかを数える。
    # 配列varyと同じ要素数.それぞれnumericに何個あったかを格納
    count = [0 for i in range(variety)]
    if variety > K:
        TypeOfNumber(vary, numeric, count)
    else:
        print(0)
        sys.exit()  # プログラムを終了させたい

    # varyをkeyに、countをvalueとして辞書を作成 <-varyをkeyに出来ていない
    # 辞書をcountで昇順ソート
    dicNum = {}
    makeDictionary(vary, count, dicNum)
    #print(dicNum)

    # ここで辞書の要素数がK個より大きい時、合計で何個の数字を入れ替えるか数える
    ballcount = 0
    ball = []
    if len(count) > K:
        ball=list(dicNum.values())
        #print(ball)
        for i in range(K):
            ball[i] = 0

    #print(ball)
    for i in range(len(ball)):
        ballcount += ball[i]
    print(ballcount)

# #[Caution!!]-関数内でグローバル変数を使う時は引数に入れてはいけない！global hoge と関数内で宣言！！

# numeric内に何種類の数字があるかを判定
def TypeDetermination(numeric, vary):
    global element1,variety   # element1=0で初期化していますが、入力される数字は1<=x<=Nなので、OK
    for element in numeric:
        if element1 is not numeric:
            variety += 1
            element1 = element
            vary.append(element1)

# TypeDeterminationでできたこと
# n種類 is variety = n-1
# vary = [1,2,4]など、1種類１つずつ格納！
# ここから先、継続して使うのは配列varyと変数varietyと配列numeric


# 3種類以上の時、それぞれ何個ずつなのかを数える
# vary配列を使う
def TypeOfNumber(vary, numeric, count):
    global variety
    N = variety
    for i in range(N):  # varyの中身、１つずつやっていく
        for j in range(len(numeric)):
            if vary[i] == numeric[j]:
                count[i] += 1


def makeDictionary(vary, count, dicNum):
    for i in range(len(count)):
        dicNum[vary[i]] = count[i] #これがうまく行ってない
    sorted(dicNum.items(), key=lambda x: x[1])#降順でソート

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

solve()

Submission status: Wrong Answer

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

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

solve()

Submission status: Wrong Answer

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

d = defaultdict(int)
for a in li:
    d[a] += 1

arr = sorted(list(d.keys()))

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
for aa in a:
    if aa > k:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=Counter(input().split())
ans=0
keys,counts=zip(*a.most_common())
for num,(key,count) in enumerate(zip(keys,counts)):
    print(num,key,count)
    if int(num)>k-1:ans+=count
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=Counter(input().split())
ans=0
keys,counts=zip(*a.most_common())
for num,(key,count) in enumerate(zip(keys,counts)):
    if int(num)>k:ans+=count
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


N, K = il()
A = il()
d = {}
c = 0
for a in A:
    try:
        d[a] += 1
    except KeyError:
        d[a] = 1
k = K - len(d)
sd = sorted(d.items(), reverse=True, key=lambda x: x[1])
s = 0
for _, v in sd[k:]:
    s += v
print(s)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


N, K = il()
A = il()
c = 0
for a in A:
    if a > K:
        c += 1
print(c)

Submission status: Wrong Answer

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

ball = sorted({a: A.count(a) for a in A}.items(), key = lambda x: x[1])
cnt = 0
for k, v in ball:
  if(len(ball) > K):
    cnt += v
  else:
    break
  ball.remove((k, v))
print(cnt)

Submission status: Wrong Answer

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

ball = {x: A.count(x) for x in X}
len_ball = len(ball)
cnt = 0
for k, v in ball.items():
  if(k > K):
    cnt += v
print(cnt)

Submission status: Wrong Answer

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
i = 0
while len(s_list) - res > K:
    res += s_list[i]
    i += 1
print(res)

Submission status: Wrong Answer

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

count = 0;

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

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

print(count)

Submission status: Wrong Answer

Solution code:
import collections


def calc(A, K):
    dist = {}
    tmp = collections.Counter(A)
    type_ = len(tmp)

    if type_ <= K:
        return 0

    for a, count in tmp.items():
        if count not in dist.keys():
            dist[count] = [a]
        else:
            dist[count].append(a)

    rewrite = 0
    for i, c in enumerate(sorted(dist.keys()), 1):
        for _ in dist[c]:
            rewrite += c
            if i == type_ - K:
                return rewrite


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = calc(A, K)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections


def calc(A, K):
    dist = {}
    tmp = collections.Counter(A)
    type_ = len(tmp)

    if type_ <= K:
        return 0

    for a, count in tmp.items():
        if count not in dist.keys():
            dist[count] = [a]
        else:
            dist[count].append(a)

    rewrite = 0
    print(dist)
    for i, c in enumerate(sorted(dist.keys()), 1):
        for _ in dist[c]:
            rewrite += c
            if i == type_ - K:
                return rewrite


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = calc(A, K)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
N, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

counts = []
view = 0
cnt = 0
for i, Ai in enumerate(A):
    if i == 0: view = Ai
    elif Ai > view:
        counts.append(cnt)
        view = Ai
        cnt = 0
    cnt += 1
else:
    counts.append(cnt)

counts.sort()

if len(counts) < 2: print(1)
else: print(sum(counts[:-K]))

Submission status: Wrong Answer

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)
elif len(kind)==n:
    print(k)
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: Wrong Answer

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

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

over = max(0, len(D) - K)
Dkey = sorted(D.items(), key = lambda x:x[1])

change = 0
current = 0
while over > 0:
    change += Dkey[current][1]
    over -= Dkey[current][1]
    current += 1
print(change)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().strip().split(" ")))
dict={}

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

X=[]
sorted_A = sorted(dict.items(), key=lambda x: x[1], reverse=True)
for i,v in sorted_A:
    X.append(v)

print(X)
ans=0
if len(X)>k:
    for i in X[k:]:
        ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import *
n, k = map(int, raw_input().split())
c = Counter(raw_input().split())
s = sorted(c.values())
print sum(s[:k - 1])

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
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])
#print(D)
answer = 0
for j in range(len(D)) :
    if len(D) - answer > K :
        answer += D[j][1]
    else :
        print(answer)
        break

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
T = list(set(A))
L = []
for i in range(len(T)) :
    L.append(A.count(T[i]))
L = sorted(L)
p = len(T)
counter = 0
for j in range(len(L)) :
    if p <= K :
        print(counter)
        break
    else :
        p -= L[j]
        counter += L[j]

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
T = list(set(A))
L = []
for i in range(len(T)) :
    L.append(A.count(T[i]))
L = sorted(L)
flag = 0
answer = 0
lenT = len(T)
while flag == 0 :
    if K < lenT :
        lenT -= L[0]
        answer += L[0]
        L.pop(0)
    else :
        print(answer)
        flag += 1

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A.insert(len(A),0)
L = []
k = 1
for i in range(len(A)-1):
  if (A[i] == A[i+1]):
    k += 1
    i += 1
  else:
    L.append(k)
    k = 1
    i += 1
  
L.sort()
print(L)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
ball = input().split()
nums = sorted(list(set(ball)))
ball_num = len(nums)

if K >= ball_num:
  print("0")
  exit()

cnt = ball_num - K
temp_list = []
for i in range(ball_num):
  num = ball.count(nums[i])
  if cnt>0:
    temp_list.append(num)
    sorted(temp_list)
    cnt-=1
  elif temp_list[-1]>num:
    temp_list[0] = num
    sorted(temp_list, reverse = True)
    
print(sum(temp_list))

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
ball = input().split()
nums = sorted(list(set(ball)))
ball_num = len(nums)

if K >= ball_num:
  print("0")
  exit()

cnt = ball_num - K
temp_list = []
for j in range(ball_num):
  num = ball.count(nums[j])
  if cnt>0:
    temp_list.append(num)
    sorted(temp_list)
    cnt-=1
  elif temp_list[-1]>num:
    temp_list[0] = num
    sorted(temp_list, reverse = True)
    
    
print(sum(temp_list), temp_list)

Submission status: Wrong Answer

Solution code:
N , K = map(int, input().split())
A = list(map(int, input().split()))
syurui = sorted(set(A))
n_syurui =len(syurui)
ans = 0
goukei = [A.count(i) for i in syurui]

if n_syurui > K:
    ans = sum(goukei[n_syurui-K+1:])
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    import collections
    counter_dict = collections.Counter(a_list)
    diff = len(counter_dict) - K
    if diff <= 0:
        print(0)
        exit()
    diff = len(counter_dict) - K
    # diff個消す。カウント数が少ないやつを。
    ans = 0
    c_list = sorted(counter_dict.items(), key=lambda x: x[1])
    print(c_list)
    for i in range(diff):
        ans += c_list[i][1]
    print(ans)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    print(max(len(set(a_list)) - K, 0))

Submission status: Wrong Answer

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

X=Counter(A)
print(len(X))
X2 = sorted(X.items(), key=lambda x:x[1])
ans=0
for i in range(len(X2)-K):
    ans+=X2[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = Counter(a).values()
print(sum(c[:k]))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = Counter(a).values()
print(sum(c[k + 1:]))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = sorted(Counter(a).values())

print(sum(c[k:]))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = Counter(a)
c = c.values()
print(sum(c[k:]))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
ct = Counter(map(int, raw_input().split())).values()
print(sum(ct[k:]))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
ct = Counter(map(int, raw_input().split())).most_common()[::-1]
ans = 0
i = 0
for v, f in ct:
    if k < len(ct):
        ans += f
        del ct[i]
    else:
        break

    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
ct = Counter(map(int, raw_input().split()))
ans = 0
for v, f in ct.most_common()[::-1]:
    if len(ct) > k:
        ans += f
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

tmp = input().split(" ")
N = int(tmp[0])
K = int(tmp[1])
a = input().split(" ")

a.sort()
c = Counter(a)
m = len(c)
min = c.most_common()[::-1]
p = 0
ans = 0
while(m > K):
  ans = min[p][1]
  m -= 1
  p += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,K=map(int,input().split())
c=sorted(collections.Counter(ball=list(map(str,input().split()))).values())
print(sum(c[:len(c)-K]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
t=[]
for i in d:
    t.append(d[i])
print(sum(t[0:-2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
CA = Counter(A)
SA = sorted(CA)
LA = len(CA)
L = max(LA - K,0)
ans = 0
for i in range(L):
    ans += SA[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
CA = Counter(A)
SA = sorted(CA)
LA = len(CA)
L = LA - K
ans = 0
for i in range(L):
    ans += SA[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,K = map(int,input().split())
ctr = Counter(list(map(int,input().split())))
a = list(ctr.values())
if len(a) <=K:
    print(0)
else:
    print(sum(a[K:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,K = map(int,input().split())
ctr = Counter(list(map(int,input().split())))
a = ctr.values()
print(N - sum(list(a)[:K]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,K = map(int,input().split())
a = list(map(int,input().split()))
matome = set(a)
counter =0
ctr = Counter(a)
kensyo = ctr.values()
print(N - sum(list(kensyo)[:K]))

Submission status: Wrong Answer

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

a = sorted(a)
p = list(set(a))

if len(p) <= k:
    print('0')
    exit()

j = 0
ans = [0 for _ in range(len(p))]
for i in range(len(p)):
    while j < n:
        if a[j] == p[i]:
            ans[i] += 1
            j += 1
        else:
            break

ans = sorted(ans)

print(sum(ans[:len(p) - k]))

Submission status: Wrong Answer

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

a = sorted(a)
p = list(set(a))

if len(p) <= k:
    print('0')
    exit()

j = 0
ans = [0 for _ in range(len(p))]
for i in range(len(p)):
    while j < n:
        if a[j] == p[i]:
            ans[i] += 1
            j += 1
        else:
            break

ans = sorted(ans)

print(sum(ans[:k - len(p) - 1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
A2 = dict(Counter(A))

if len(A2) > K:
    if len(A2) % 2 == 0:
        r = sorted(A2.items(),key=lambda x:x[1])
        print(sum([i[1] for i in r[:K]]))
    else:
        r = sorted(A2.items(),key=lambda x:x[1])
        print(sum([i[1] for i in r[:K-1]]))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
from collections import Counter

N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
A2 = dict(Counter(A))

if len(A2) > K:
    r = sorted(A2.items(),key=lambda x:x[1])
    print(N - sum([i[1] for i in r[K-1:]]))
else:
    print("0")

Submission status: Wrong Answer

Solution code:
from collections import Counter

N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
A2 = dict(Counter(A))

if len(A2) >= K:
    r = sorted(A2.items(),key=lambda x:x[1])
    print(N - sum([i[1] for i in r[K-1:]]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
r = []
c = []

for i in A:
    if c.count(i) == 0:
        r.append(A.count(i))
        c.append(i)
    else:
        continue

if len(r) >= K:
    r = sorted(r)
    print(N - sum(r[K-1:]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
r = []
c = []
for i in A:
    if c.count(i) == 0:
        r.append((i,A.count(i),))
        c.append(i)
    else:
        continue

if len(r) > K:
    r = sorted(r,key=lambda x:x[1])
    print(sum([i[1] for i in r[0:K-1]]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
r = []
c = []
for i in A:
    if c.count(i) == 0:
        r.append((i,A.count(i),))
        c.append(i)
    else:
        continue

if len(r) >= K:
    r = sorted(r,key=lambda x:x[1])
    print(sum([i[1] for i in r[0:K-1]]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#ABC081 C - Not so Diverse
import collections

I = raw_input().split(" ")
N = int(I[0])
K = int(I[1])
A = map(int,raw_input().split(" "))
countA = collections.Counter(A).values()
if len(countA) > K:
    pre_ans = 0
    for i in range(K):
        pre_ans += countA[i]
    ans = N - pre_ans
    print ans
else:
    print 0

Submission status: Wrong Answer

Solution code:
#ABC081 C - Not so Diverse
import collections

I = raw_input().split(" ")
N = int(I[0])
K = int(I[1])
A = map(int,raw_input().split(" "))
countA = collections.Counter(A).values()
if len(countA) >= K:
    pre_ans = 0
    for i in range(K):
        pre_ans += countA[i]
    ans = N - pre_ans
    print ans
else:
    print 0

Submission status: Wrong Answer

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

A_set = list(set(A))
len_A_set = len(A_set)

i = 0
ct = 0
while True:
    if ct >= len_A_set - K:
        break
    min = 10000000
    for i in A_set:
        if A.count(i) < min:
            min = A.count(i)
    ct += min

print(ct)

Submission status: Wrong Answer

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

A_set = list(set(A))
len_A_set = len(A_set)

i = 0
ct = 0
while True:
    min = 10000000
    for i in A_set:
        if A.count(i) < min:
            min = A.count(i)
    ct += min
    if ct >= len_A_set - K:
        break
print(ct)

Submission status: Wrong Answer

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

count_list = []
if len(set_a) <= k:
    print(0)
else:
    for num in set_a:
        count_list.append(a.count(num))
    count_list = sorted(count_list, reverse = True)

    print(count_list)
    print(sum(count_list[k:]))

Submission status: Wrong Answer

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

count_list = []
if len(set_a) <= k:
    print(0)
else:
    for num in set_a:
        count_list.append(a.count(num))
    count_list = sorted(count_list)    

    print(sum(count_list[k:]))

Submission status: Wrong Answer

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

count_list = []
if len(set_a) <= k:
    print(0)

else:
    for num in set_a:
        count_list.append(a.count(num))

    print(sum(count_list[k:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff > 0:
            diff -= 1
            count += value[1]
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)
print(counter)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff > 0:
            diff -= 1
            count += value[1]
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff > 0:
            diff -= value[1]
            count += value[1]
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff >= 0:
            diff -= value[1]
            count += 1
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff >= 0:
            diff -= 1
            count += 1
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

N, K = map(int, input().split())
A = list(int(i) for i in input().split())
counter = sorted(C(A).items(), reverse=True)

if len(counter) <= K:
    print(0)
else:
    diff = len(counter) - K
    count = 0
    for value in counter:
        if diff > 0:
            diff -= 1
            count += 1
        else:
            break
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

n, k = map(int, input().split())
array = [int(x) for x in input().split()]
_dict = collections.Counter(array)

res = 0
tmp = len(_dict.values())
if len(_dict.values()) < k:
    print(0)
else:
    tmp_array = list(reversed(sorted(_dict.items())))
    for i in tmp_array:
        res += i[1]
        tmp -= i[1]
        if tmp <= k:
            break
    print(res)