There are N students in a class. Recently, an exam on Advanced Algorithms was conducted with maximum score M and minimum score 0. The average score of the class was found out to be exactlyX.

Given that a student having score strictly greater than the average receives an A grade, find the maximum number of students that can receive an A grade.

EXPLANATION:

Let us look at the two cases for this problem:

X=M: Here it implies that every single student has scored M marks and since no student can score more than M marks. Thus in this case no student would receive A grade.

X < M: Let us take a variable sum as the sum of marks of all students. Then

sum = N \times X

Now to maximise students who score more than average marks we assign (X+1) marks to as many students as possible, which would be our answer.

In the problem, it was not mentioned that the scores of the student must be integer. Also, the sample test cases passed the solutions which assumed the solutions to include non-integer scores.

I donâ€™t get it. Why would answer be the floor of n*x/(x+1) ? I understand we are trying to maximise but I canâ€™t make the connection between that and the mathematical expression. Can someone please elaborate?

Average = Sum of score/ N.
So sum of score = NX
Number the persons from 1 to N. Start assigning them (X+1) scores from 1 to N. Whatâ€™s the maximum number of person you can assign X+1 exactly floor(NX/(X+1)). After that youâ€™ll be left with N*X mod (X+1) score which is less than X+1 which it doesnâ€™t to whom you give