Input: K = 7, a[] = {1, 1, 3, 4, 5, 3, 7, 1}
b[] = {7, 5, 4, 8, 1, 3, 5, 2}
Output: 10
Explanation: In a[] some numbers are repeating which are 1, 1, 3, 3, 1.
Now, make two 1's and one 3 unique.
Select a[1], a[5] and a[7] and replace them with 2, 6, and 8 to make array a permutation of 1 to 8.
The total cost is b[1] + b[5] + b[7] = 5 + 3 + 2 = 10.
This is the minimum cost to make a[] a permutation of 1 to 8.
Now, a[] becomes {1, 2, 3, 4, 5, 6, 7, 8}
Input: K = 3, a[] = {3, 1, 2}
b[] = {5, 3, 4}
Output: 0
Explanation: a[] is already a permutation of 1 to 3. So no need to replace any value.