#K60867. Distinct Coin Groups

    ID: 31182 Type: Default 1000ms 256MiB

Distinct Coin Groups

Distinct Coin Groups

You are given several test cases. In each test case, you are given a collection of coins with non‐negative integer counts. For each test case, your task is to form as many groups as possible by potentially incrementing duplicate coin counts so that each group has a distinct coin count.

Formally, for each test case you are provided an integer M representing the number of coins, and a list of M integers denoting the coin counts. You want to assign to each coin a new count (by possibly keeping the original count or increasing it) such that all final counts are distinct. The goal is to maximize the number of groups, which is equivalent to processing every coin once following this rule.

Note: The updated count for a coin is obtained by taking its original count and, if it conflicts with any count already used, incrementing it repetitively until a unique value is found. Output the total number of groups (coins) for each test case.

The problem can be mathematically described as follows: For a sorted list \(a_1, a_2, \ldots, a_M\), define a sequence \(b\) such that \[ b_1 = a_1,\quad b_i = \min\{x \ge a_i: x \notin \{b_1, b_2, \ldots, b_{i-1}\}\} \text{ for } i>1. \] The answer for that test case is \(M\), the number of coins processed.

inputFormat

The input begins with an integer T representing the number of test cases. For each test case:

  • A line containing an integer M denoting the number of coins.
  • A line with M space-separated integers representing the coin counts.

All input is read from stdin.

outputFormat

For each test case, output a single integer representing the maximum number of groups that can be formed (one per line). The output is written to stdout.

## sample
2
5 10 20 30 40 50
3 3 3
5

3

</p>