#P2637. [USACO08NOV] 第一次,第二次,成交!Going Once, Going Twice, Gone! B

[USACO08NOV] 第一次,第二次,成交!Going Once, Going Twice, Gone! B

Description

Because of the cows’ dieting campaign, FJ has a large amount of leftover hay he cannot use, so he plans to hold an auction to sell it.

He has nn batches of hay. He has mm customers, all of whom are farmers like him. Farmer ii says he will pay pip_i for each batch of FJ’s hay. Every farmer wants to buy exactly one batch (and only one).

To make sure the farmers do not envy each other, FJ decides to sell at a single fixed price. Every farmer whose bid is greater than or equal to FJ’s asking price will buy a batch.

Please help FJ find the lowest per-batch price that earns him the maximum total revenue.

Input Format

  • The first line contains two integers nn and mm separated by a space.
  • Lines 22 through m+1m+1: line i+1i+1 contains a single integer pip_i.

Output Format

Output one line with two space-separated integers: the lowest per-batch price FJ should set, and the maximum total revenue he can earn.

5 4
2
8
10
7
7 21

Hint

Sample Explanation
FJ has 55 batches of hay, and 44 farmers want to buy. Their bids per batch are 22, 88, 1010, and 77.
FJ should set the price to 77. Then 33 farmers will buy, and FJ will earn 2121.

Constraints
For 100%100\% of the testdata, 1m,n10001 \leq m, n \leq 1000, 1pi1,000,0001 \leq p_i \leq 1,000,000.

Translated by ChatGPT 5