Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

3142.   Going Once, Going Twice, Gone!
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 655   Accepted Runs: 289    Multiple test files



The cows' slimming diet has left Farmer John with extra hay so he has decided to hold an auction to reduce his inventory. He has N (1 ≤ N ≤ 1,000) identical lots (each of about 100 bales) of hay; his potential customers comprise M (1 ≤ M ≤ 1,000) other farmers in the area.

Each farmer i tells Farmer John how much he is willing to pay P_i (1 ≤ P_i ≤ 1,000,000) for a lot of hay. Each of the farmers wishes to purchase a single lot of hay.

To make sure the other farmers do not get jealous of each other, Farmer John decides that he must sell the lots of hay at a fixed price to each customer who is willing to pay at least that price; the rest will decline the purchase.

Help Farmer John determine the smallest price he should set on a lot of hay to maximize the amount of money he makes.

Input

* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Line i+1 contains a single integer: P_i

Output

* Line 1: Two space-separated integers: the smallest price that Farmer John should choose to maximize his revenue and the amount of money he takes in.

Sample Input

5 4
2
8
10
7

Sample Output

7 21

Hint

Farmer John has 5 lots of hay. 4 farmers wish to purchase hay; they will pay 2, 8, 10, and 7, respectively, for a lot of hay. Farmer John should set the price at 7 so that 3 of the farmers will be willing to pay for a lot of hay, and he will earn 21.



Source: USACO 2008 November Competition
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz