ABC81 C - Not so Diverse를 풀었다
3624 단어 AtCoder파이썬AtCoderBeginnerContest




각 요소를 세어 본다.
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가 항상 잊어버린다.
신 사이트에 감사
Reference
이 문제에 관하여(ABC81 C - Not so Diverse를 풀었다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/AKpirion/items/848d1543b6a0fb7d7fdf텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)