#P8897. Maximizing Cow College Revenue
Maximizing Cow College Revenue
Maximizing Cow College Revenue
Farmer John is opening a new college for his cows! There are (N) cows, and each cow is willing to pay at most (c_i) tuition. Farmer John needs to set a single tuition fee. A cow will only attend if the tuition fee is less than or equal to her maximum willingness to pay. Therefore, if the tuition fee is set to (t), the revenue is given by:
[ R(t) = t \times (\text{number of cows with } c_i \ge t)]
Your task is to determine the maximum revenue Farmer John can achieve and the corresponding tuition fee. If there are multiple tuition fees that yield the same maximum revenue, output the smallest tuition fee among them.
Input Constraints:
- \(1 \le N \le 10^5\)
- \(1 \le c_i \le 10^6\) for each \(i\)
inputFormat
The first line contains an integer (N), the number of cows. The second line contains (N) space-separated integers (c_1, c_2, \dots, c_N), where (c_i) is the maximum tuition that the (i)-th cow is willing to pay.
outputFormat
Output two integers separated by a space: the maximum revenue Farmer John can earn and the corresponding tuition fee. If there are multiple tuition fees with the same maximum revenue, output the smallest one.
sample
4
1 6 4 6
12 4