Please help to explain the problem and tell the approach too

Please help to explain the problem and tell the approach too.

Okay here is the code https://www.codechef.com/viewsolution/33537438
Now the best price would be one among the existing budgets.
So sort the budgets, and if ith person can pay , remaining n-i persons can also pay.
So just iterate over the array and find the max value

I don’t understand the Question and Solution too. Like I have done Sorting and then why we have done that for maximum price. Please explain that.

Question wants you to decide the cost that company should sell its phone for. Now if it keeps a price x, then people who have budget greater than x will be able to pay for it and those which have budget less than x won’t be able to. So one might argue lets keep the price equal to smallest budget that way I can sell maximum amount of phones ,in this case n (total number of people). Let this cost be c, so the total revenue is cn. But the thing is there might exist a value c’ such that y people are able to pay for it, and the revenue in that case y * (c’) is greater than initial revenue cn. So our task is to find this optimal value of c’.
For example in this sample
5
40
3
65
33
21

value of c’ is 33.
Now it can be easily seen that c’ has to be one of the budget values because if you are making the i’th person pay then keep the cost of phone equal to its budget.

Okay let’s say you sort the array.
Now iterate over all possible values of c’, i.e., all budgets and calculate the answer for all c’.
Thus print the max revenue at the end.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.