#P328. 练55.3 收益最大

练55.3 收益最大

Description

Farmer John has mm batches of hay left that he cannot process, and he plans to hold an auction to sell them. There are nn customers, each offering a price of aia_i. John needs to set a unit price; all customers offering a price greater than or equal to the unit price will buy 11 batch of hay (not all mm 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 mm and nn, representing the number of hay batches and the number of customers, respectively. The second line contains nn integers, where aia_i represents the price offered by the ii-th customer.
Data range: 1<n,m10001 < n, m ≤ 1000, 1<ai100001 < a_i ≤ 10000.

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 7
7 21