注意一个点:题中说,如果有多个解,输出收取学费最小的解。因为我们是按照学费从小到大进行排序,所以小的在前,后面再遇到res与max相同的情况直接跳过,所以在程序中体现为if (res > max)才更新
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
LL c[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; ++ i) scanf("%lld", &c[i]);
sort(c, c + n);
LL res = 0, max = 0, tution = 0;
for (int i = 0; i < n; ++ i)
{
res = (LL) (n - i) * c[i];
if (res > max)
{
max = res;
tution = c[i];
}
}
printf("%lld %lld\n", max, tution);
return 0;
}