AmazonOA #222
Get Minimum Removal
Estimated EasyJudge-ready
Delete some products so that at most k distinct categories remain; find the minimum number of products deleted. Every individual item of the same category counts.
Input
The first line contains n k; the second line contains the categories. 1≤n,k,category≤100000.
Output
Output a single integer, the answer.
Example 1
Input:
4 1
3 3 5 7
Output:
2
Example 2
Input:
2 5
1 2
Output:
0
Example 3
Input:
5 1
1 1 2 2 2
Output:
2
Example notes
The answers are 2, 0 and 2. When k exceeds the actual number of categories, nothing needs to be deleted.
Editorial
Loading solution…