#C2865. Minimum Operations to Make Array Elements Distinct

    ID: 46228 Type: Default 1000ms 256MiB

Minimum Operations to Make Array Elements Distinct

Minimum Operations to Make Array Elements Distinct

You are given an array of n integers. You are allowed to perform the following operation: choose an element and increment it by 1. The goal is to obtain an array where all elements are distinct. Formally, given an array \(a_1, a_2, \dots, a_n\), you can perform an operation defined as \(a_i = a_i + 1\) on any element. Determine the minimum number of operations required to achieve an array with all distinct elements.

Input Constraints:

  • The first line contains an integer \(T\), the number of test cases.
  • For each test case, the first line contains an integer \(n\), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array.

Example:

Input:
1
3
2 1 2

Output: 1

</p>

inputFormat

The input is read from standard input (stdin) and follows the format below:

T
n
a1 a2 ... an
... (for each test case)

Where:

  • T is the number of test cases.
  • For each test case, n denotes the number of elements in the array, followed by n integers.

outputFormat

For each test case, output the minimum number of operations required on a separate line. The output is written to standard output (stdout).

## sample
1
3
2 1 2
1

</p>