You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
621 B

#include<bits/stdc++.h>//万能头
using namespace std;
int n, m;
int main() {
int i, k, maxn = 0, ans = 0;
cin >> n >> m;
int a[n + 1];
for (i = 1; i <= m; i++)
cin >> a[i];
//将叫价从小到大排个序
sort(a + 1, a + m + 1);
for (i = m; i >= 1; i--)//枚举一遍叫价
{
//得到的钱大于之前最多的,并且草料够用
if (a[i] * (m - i + 1) > maxn && m - i + 1 <= n)
{
maxn = a[i] * (m - i + 1);
ans = a[i];//替换
}
}
cout << ans << " " << maxn;//输出
return 0;
}