GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Thursday, 19 May 2022

[Solution] MEX vs DIFF Codeforces Solution | Codeforces Problem Solution 2022

E. MEX vs DIFF
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a of n non-negative integers. In one operation you can change any number in the array to any other non-negative integer.

Let's define the cost of the array as DIFF(a)MEX(a), where MEX of a set of non-negative integers is the smallest non-negative integer not present in the set, and DIFF is the number of different numbers in the array.

For example, MEX({1,2,3})=0MEX({0,1,2,4,5})=3.

Solution Click Below:-  CLICK HERE

You should find the minimal cost of the array a if you are allowed to make at most k operations.

Input

The input consists of multiple test cases. The first line contains a single integer t (1t104) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers n and k (1n1050k105) — the length of the array a and the number of operations that you are allowed to make.

The second line of each test case contains n integers a1,a2,,an (0ai109) — the elements of the array a.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output

For each test case output a single integer — minimal cost that it is possible to get making at most k operations.

No comments:

Post a Comment