#C527. Max Value by Frequency
Max Value by Frequency
Max Value by Frequency
You are given T test cases. For each test case, you are provided with a list of integers. Your task is to compute the maximum value obtained by multiplying an integer by its frequency in the list.
In other words, for each test case, if an integer x appears f times, then its contribution is given by:
\(x \times f\)
Your answer for each test case is the maximum value of \(x \times f\) among all distinct integers in the given list.
Input/Output: The input is read from stdin
and the output is written to stdout
. In each test case, the first integer is N (the number of elements in the list), followed by a line of N integers. The first line of input contains T, the number of test cases. For each test case, output the computed result on a new line.
Example:
Input: 2 5 3 3 2 2 1 4 4 4 4 1</p>Output: 6 12
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, the number of elements in the list.
- The second line contains N space-separated integers.
All input is provided via stdin
.
outputFormat
For each test case, print a single line containing one integer — the maximum value computed as \(x \times f\), where x is a number from the list and f is its frequency.
All output should be printed to stdout
.
2
5
3 3 2 2 1
4
4 4 4 1
6
12
</p>