farmer John The rest m Batch of hay cannot be processed , He is going to hold an auction to sell his hay . Now there are n Customers , What is the price per customer ai​. Now? John
To determine a unit price , All customers whose quotation is greater than or equal to the unit price will buy it 1 Batch of hay （m This batch of licorice doesn't have to be sold out ）, The total amount of money obtained as a gain . So here comes the question... , How to set unit price , Maximize benefits .

Input format

The first line contains two integers m,n Respectively represent m Batch of hay and n Customers .

Second line n Integer ,ai​ Represents the second i A customer's quotation .

Data range ：1≤n,m≤1000,1≤ai​≤10000.

Output format

Two integers separated by spaces , Represents unit price and total revenue respectively .

If there are multiple equal maximum returns , Select the one with the lowest unit price .

AC The code is as follows ：
#include<iostream> #include<cstdio> #include<algorithm> using namespace std;
int s; int main() { int n,m; scanf("%d %d",&m,&n); for(int i =
1;i<=n;i++) scanf("%d",&s[i]); sort(s+1,s+n+1,greater<int>()); int pr = 0; int
sum = 0; for(int i = 1;i<=n&&i<=m;i++) { if(sum<=s[i]*i) { pr = s[i]; sum =
s[i]*i; } } printf("%d %d\n",pr,sum); }
Code parsing （ Problem solution ）：

Just enumerate according to the meaning of the topic

Let's sort first （ From big to small ）, Benefits of doing so ：

with i Customer's quotation ai Is the unit price , Income is ai * i . In this way, the code written in the process of enumeration is more comfortable and concise !!!
sort(s+1,s+n+1,greater<int>()); int pr = 0; int sum = 0; for(int i =
1;i<=n&&i<=m;i++) { if(sum<=s[i]*i) { pr = s[i]; sum = s[i]*i; } }
be careful ：    if(sum<=s[i]*i)

Because the requirements of the topic are ： If there are multiple equal maximum returns , Select the one with the lowest unit price .

Final output unit price And profit Just ok Yes !

last , Thank you for reading !!!

Prepare for the Blue Bridge Cup !!!

Start from today. , As a freshman, I'm going to open another column —— Prepare for the Blue Bridge Cup

I hope you can give me more support !

Also hope Comrades preparing for the Blue Bridge Cup , have passed the examination !!!

I don't think about whether I can succeed , Now that you have chosen the distance , Just take care of the wind and rain !

Technology
Daily Recommendation