1810C.md (2544B)
1 Source: https://codeforces.com/problemset/problem/1810/C 2 3 C. Make It Permutation 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You have an integer array $a$ of length $n$. There are two kinds of operations you can make. 22 23 * Remove an integer from $a$. This operation costs $c$. 24 * Insert an arbitrary positive integer $x$ to any position of $a$ (to the front, to the back, or between any two consecutive elements). This operation costs $d$. 25 26 You want to make the final array a permutation of any positive length. Please output the minimum cost of doing that. Note that you can make the array empty during the operations, but the final array must contain at least one integer. 27 28 A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). 29 30 Input 31 32 Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Their description follows. 33 34 The first line of each test case contains three integers $n$, $c$, $d$ ($1 \le n \le 10^5$, $1 \le c,d \le 10^9$). 35 36 The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($1 \le a_{i} \le 10^9$). 37 38 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 39 40 Output 41 42 For each test case, output in one line the minimum cost to make the final array a permutation. 43 44 Example 45 46 Input 47 48 ``` 49 8 50 51 3 3 3 52 53 1 2 3 54 55 5 1 5 56 57 1 2 3 5 6 58 59 5 2 3 60 61 1 1 1 3 3 62 63 5 1 10 64 65 2 4 6 8 10 66 67 6 2 8 68 69 7 3 5 4 4 8 70 71 4 10 1 72 73 1 2 6 7 74 75 4 3 3 76 77 2 5 8 7 78 79 2 1000000000 1 80 81 1000000000 1 82 ``` 83 84 Output 85 86 ``` 87 0 88 2 89 8 90 14 91 20 92 3 93 12 94 999999998 95 ``` 96 97 Note 98 99 In the first test case, the array is already a permutation, so there's no need for operations. 100 101 In the second test case, we can remove numbers $5$, $6$ to get the permutation $[1,2,3]$ in cost $2$. Note that we can also get a permutation by inserting a number $4$, but it costs $5$. 102 103 In the third test case, we can just remove all the numbers except for the first number $1$. It costs $8$, and the final array is $[1]$, which is a permutation of length $1$. 104 105 In the fourth test case, we can remove all the numbers except for $2$, and insert a number $1$ to the first position. It costs $4+10=14$, and the final array is $[1,2]$, which is a permutation of length $2$.