Impartial Offerings
InterviewTime limit10sMemory limit1024 MB
Assign each pet a treat count so equal sizes get equal counts and larger sizes get strictly more, minimizing the total treats.
- Level
Easy3 of 10
- Topics
- Sorting, Greedy, Implementation, Math
- Solved
- No attempts yet
Problem
Aroha is a big animal lover, so she spends some free time taking care of many of her loved ones' pets. She likes to offer them treats, but wants to do that in an impartial way.
Aroha decided that it was logical for pets of the same size to get the same amount of treats and for larger pets to get strictly more treats than smaller ones. For example, if she has pets with her of sizes , and , she could offer treats to each pet of size , treats to the pet of size , and treats to the pet of size . This requires her to buy a total of treats. However, she can offer treats to all pets and comply with her own rules with a total of just treats by offering each to the pets of size , to the pet of size , and to the pet of size .
Help Aroha plan her next pet day. Given the sizes of all pets that will accompany her, compute the minimum number of treats she needs to buy to be able to offer at least one treat to all pets while complying with her impartiality rules.
Input
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines. The first line of a test case contains a single integer , the number of pets in Aroha's next pet day. The second line of a test case contains integers , representing the sizes of each pet.
Output
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the minimum number of treats she needs to buy to be able to offer at least one treat to all pets while complying with her impartiality rules.
Constraints
- .
- , for all .
Hint
Sample Case #1 is the case explained above.
In Sample Case #2, all pets are of the same size, so Aroha must offer them all the same amount of treats. The minimum total is attained by offering each pet a single treat.
In Sample Case #3, both pets are of different size so they need a different amount of treats each. Buying less than treats is not enough to give treats to both pets. Buying treats and making sure both pets get something would force Aroha to give both pets the same amount, despite them having different size. Using treats Aroha can give to the small pet and to the big pet and thus comply with all her rules.