[USACO 2008 Nov B]Going Once, Going Twice, Gone!
题号:NC24978
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

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 Pi (1 <= Pi <= 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.

输入描述:

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

输出描述:

* 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.
示例1

输入

复制
5 4
2
8
10
7

输出

复制
7 21

说明

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.