PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000002. Giữ lại không quá K loại (Not so Diverse)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giữ lại không quá K loại (Not so Diverse)
Not so Diverse
Source: AtCoder Version: Phuoc Hung OJ Extended
Problem Statement
There are balls, each labeled with an integer. You may replace the number on any ball with any integer. Find the minimum number of balls that must be relabeled so that at most different values remain.
Input
The first line contains and . The next line contains values .
Output
Print one integer: the minimum number of relabelings.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
7 2
1 2 1 3 3 3 4
Output
2
Explanation
Keep values and (frequencies and ). Relabel the two balls with values and .