ABC81 C - Not so Diverse を解いた
3894 ワード
各要素を数えてみる。
K 種類以下になるまで、要素数の少ない順に足し合わせたら答えになると思った。
NotSoDiverse.py
N,K = map(int,input().split())
A = list(map(int,input().split()))
dic = {}
for n in range(N):
if A[n] not in dic:
dic[A[n]] = 0
dic[A[n]] += 1
target = len(dic)-K
dic = sorted(dic.items(), key=lambda t:t[1])
#print(dic)
ans = 0
for i in range(target):
ans += dic[i][1]
print(ans)
辞書の sort がいっつも忘れる。
神サイトに感謝
Author And Source
この問題について(ABC81 C - Not so Diverse を解いた), 我々は、より多くの情報をここで見つけました https://qiita.com/AKpirion/items/848d1543b6a0fb7d7fdf著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .