Cow College
InterviewTime limit2sMemory limit1024 MB
Pick the tuition that maximizes price times the number of cows willing to pay it. Print the best revenue and the smallest such tuition.
Problem
Farmer John is planning to open a new university for cows. There are () cows who could potentially attend. Each cow is willing to pay a maximum tuition of (). Farmer John sets one tuition that all cows must pay to enroll. If the tuition is higher than what a cow is willing to pay, that cow does not attend. Farmer John wants to earn as much money as possible so he can pay his instructors a fair wage. Find the maximum amount of money he can make and the tuition he should charge.
Input
The first line contains . The second line contains integers , where is the maximum tuition cow is willing to pay.
Output
Output the maximum amount of money Farmer John can make and the optimal tuition he should charge. If several solutions exist, output the one with the smallest optimal tuition. The numbers involved can be large, so you may need a 64-bit integer type.
Hint
If Farmer John charges , then cows attend, so he makes .