#K70977. Minimum Operations to Make Array Elements Distinct

    ID: 33428 Type: Default 1000ms 256MiB

Minimum Operations to Make Array Elements Distinct

Minimum Operations to Make Array Elements Distinct

You are given an array of integers (A = [a_1, a_2, \dots, a_n]). In one operation, you can increment any element by 1. Your task is to determine the minimum number of operations required to make all elements in (A) pairwise distinct. In other words, after performing the operations, the array must satisfy (a_1 < a_2 < \cdots < a_n) when sorted.

For example, given (A = [1, 2, 2]), you can increment the second 2 to 3 with 1 operation, making the array ([1, 2, 3]), which is valid. Similarly, for (A = [10, 10, 10, 10, 10]), a total of 10 operations are required to obtain ([10, 11, 12, 13, 14]).

Your solution should read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The first line contains an integer (T) denoting the number of test cases. For each test case:

  • The first line contains an integer (n), representing the number of elements in the array.
  • The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single integer on a new line, representing the minimum number of operations required to make all elements in the array distinct.## sample

2
3
1 2 2
5
10 10 10 10 10
1

10

</p>