#P328. 练55.3 收益最大
练55.3 收益最大
Description
Farmer John has batches of hay left that he cannot process, and he plans to hold an auction to sell them. There are customers, each offering a price of . John needs to set a unit price; all customers offering a price greater than or equal to the unit price will buy batch of hay (not all batches need to be sold), and the total money received will be his profit. The question is: how should he set the unit price to maximize his profit?
Input Format
The first line contains two integers and , representing the number of hay batches and the number of customers, respectively. The second line contains integers, where represents the price offered by the -th customer.
Data range: , .
Output Format
Output two integers separated by a space, representing the unit price and the total profit. If there are multiple equal maximum profits, choose the one with the smallest unit price.
Sample
5 4
2 8 10 77 21