CF1810C.Make It Permutation

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have an integer array aa of length nn. There are two kinds of operations you can make.

  • Remove an integer from aa. This operation costs cc.
  • Insert an arbitrary positive integer xx to any position of aa (to the front, to the back, or between any two consecutive elements). This operation costs dd.

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.

A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

你有一个长度为 nn 的整数数组 aa。你可以执行以下两种操作:

  • 从 aa 中删除一个整数,该操作花费 cc;
  • 在 aa 的任意位置(开头、结尾或任意两个相邻元素之间)插入一个任意的正整数 xx,该操作花费 dd。

你的目标是使最终数组成为某个正整数长度的排列。请输出实现该目标的最小总花费。注意:在操作过程中数组可以为空,但最终数组必须至少包含一个整数。

长度为 nn 的排列是指由 11 到 nn 这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Their description follows.

The first line of each test case contains three integers nn, cc, dd (1≤n≤1051 \le n \le 10^5, 1≤c,d≤1091 \le c,d \le 10^9).

The second line of each test case contains nn integers a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} (1≤ai≤1091 \le a_{i} \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、cc、dd(1≤n≤1051 \le n \le 10^5,1≤c,d≤1091 \le c,d \le 10^9)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}(1≤ai≤1091 \le a_{i} \le 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output in one line the minimum cost to make the final array a permutation.

对于每个测试用例,在一行中输出使最终数组成为排列的最小代价。

输入输出样例

  • 输入#1

    8
    3 3 3
    1 2 3
    5 1 5
    1 2 3 5 6
    5 2 3
    1 1 1 3 3
    5 1 10
    2 4 6 8 10
    6 2 8
    7 3 5 4 4 8
    4 10 1
    1 2 6 7
    4 3 3
    2 5 8 7
    2 1000000000 1
    1000000000 1

    输出#1

    0
    2
    8
    14
    20
    3
    12
    999999998

说明/提示

In the first test case, the array is already a permutation, so there's no need for operations.

In the second test case, we can remove numbers 55, 66 to get the permutation [1,2,3][1,2,3] in cost 22. Note that we can also get a permutation by inserting a number 44, but it costs 55.

In the third test case, we can just remove all the numbers except for the first number 11. It costs 88, and the final array is [1][1], which is a permutation of length 11.

In the fourth test case, we can remove all the numbers except for 22, and insert a number 11 to the first position. It costs 4+10=144+10=14, and the final array is [1,2][1,2], which is a permutation of length 22.

在第一个测试用例中,数组本身已经是一个排列,因此无需进行任何操作。

在第二个测试用例中,我们可以删除数字 55 和 66,从而以代价 22 得到排列 [1,2,3][1,2,3]。注意,我们也可以通过插入数字 44 来得到一个排列,但其代价为 55。

在第三个测试用例中,我们只需保留第一个数字 11,删除其余所有数字。其代价为 88,最终数组为 [1][1],这是一个长度为 11 的排列。

在第四个测试用例中,我们可以删除除 22 以外的所有数字,并在首位插入数字 11。其代价为 4+10=144+10=14,最终数组为 [1,2][1,2],这是一个长度为 22 的排列。

输入解题思路,AI测评打分。不知道怎么写?

首页