#P8897. [USACO22DEC] Cow College B
[USACO22DEC] Cow College B
Description
Farmer John plans to open a new college for his cows!

There are cows that might enroll. Each cow is willing to pay at most in tuition . Farmer John can set a single tuition that all cows must pay to enroll. If this tuition is greater than a cow’s maximum willingness to pay, then that cow will not enroll. Farmer John wants to earn as much money as possible so he can pay his instructors well. Compute how much money he can earn and the tuition he should charge to achieve that.
Input Format
The first line contains .
The second line contains integers , where is the maximum tuition cow is willing to pay.
Output Format
Output the maximum amount Farmer John can earn and the tuition he should charge in the optimal case. If there are multiple answers, output the one with the smallest tuition.
Note that the integers involved may require 64-bit integer types (e.g., long in Java, long long in C/C++).
4
1 6 4 6
12 4
Hint
Sample 1 Explanation
If Farmer John charges , then cows will enroll, earning him .
Testpoint Properties
- Testpoints satisfy .
- Testpoints satisfy .
- Testpoints have no additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号