#K47022. Minimum Changes for k-Expressible Array
Minimum Changes for k-Expressible Array
Minimum Changes for k-Expressible Array
You are given an array of n integers and a positive integer k. The array is said to be k-expressible if it contains at most k distinct elements. You are allowed to change any element of the array to any integer. Your task is to find the minimum number of changes required to make the array k-expressible.
Mathematically, if the frequencies of the distinct elements are (f_1, f_2, \dots, f_m) (with (m > k)), then you must choose k elements with the highest frequencies such that the minimum number of changes is given by [ n - \sum_{i=1}^{k} f_i, ] where n is the size of the array. If the array already contains k or fewer distinct elements, then no changes are needed.
inputFormat
The input is given from standard input (stdin
) and consists of two lines:
- The first line contains two integers
n
andk
separated by a space, wheren
is the number of elements in the array andk
is the maximum allowed number of distinct elements. - The second line contains
n
integers separated by spaces representing the array elements.
outputFormat
Output a single integer to standard output (stdout
) representing the minimum number of changes required to make the array k-expressible.
5 2
1 2 3 4 5
3
</p>